DateFormat setTimeZone - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for DateFormat setTimeZone method.

This code example shows how to use the following methods:format, DateFormat.setTimeZone
        format.setTimeZone(TimeZone.getTimeZone(iParameters[1].toString()));
      else 
        format.setTimeZone(ODateHelper.getDatabaseTimeZone());
    } 
 
    return format.format(now);
  } 
 
  public boolean aggregateResults(final Object[] configuredParameters) {
    return false; 
  } 
 
  public String getSyntax() {
    return "Syntax error: sysdate([<format>] [,<timezone>])"; 
  } 
 
  @Override 
  public Object getResult() {
    return null; 
  } 
8
CodeRank
This code example shows how to use the following methods:parse, setTimeZone
        format.setTimeZone(ODateHelper.getDatabaseTimeZone());
      } else 
        format = ODatabaseRecordThreadLocal.INSTANCE.get().getStorage().getConfiguration().getDateTimeFormatInstance();
 
      if (iParameters.length == 3)
        format.setTimeZone(TimeZone.getTimeZone(iParameters[2].toString()));
    } 
 
    try { 
      return format.parse((String) iParameters[0]);
    } catch (ParseException e) {
      throw new OQueryParsingException("Error on formatting date '" + iParameters[0] + "' using the format: " + format, e);
    } 
  } 
 
  public boolean aggregateResults(final Object[] configuredParameters) {
    return false; 
  } 
 
  public String getSyntax() {
8
CodeRank
This code example shows how to use the following methods:format, setTimeZone
    public void testFormattingUncommonTimeZoneAbbreviations() { 
        // In Honeycomb, only one Olson id was associated with CET (or any 
        // other "uncommon" abbreviation). 
        String fmt = "yyyy-MM-dd HH:mm:ss.SSS z";
        String date = "1970-01-01 01:00:00.000 CET";
        SimpleDateFormat sdf = new SimpleDateFormat(fmt, Locale.US);
        sdf.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
        assertEquals(date, sdf.format(new Date(0)));
        sdf = new SimpleDateFormat(fmt, Locale.US);
        sdf.setTimeZone(TimeZone.getTimeZone("Europe/Zurich"));
        assertEquals(date, sdf.format(new Date(0)));
    } 
 
    // http://code.google.com/p/android/issues/detail?id=8258 
    public void testTimeZoneFormatting() throws Exception { 
        Date epoch = new Date(0);
 
        // Create a SimpleDateFormat that defaults to America/Chicago... 
        TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago"));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
8
CodeRank
This code example shows how to use the following methods:format, setTimeZone
                return null; 
            } 
        } 
 
        private String toHeader(Date date) {
            SimpleDateFormat httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
            httpDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
            return httpDateFormat.format(date);
        } 
 
        private Date fromHeader(String date) {
            SimpleDateFormat httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
            httpDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
            try { 
                return httpDateFormat.parse(date);
            } catch (Exception ex) {
                return new Date();
            } 
        } 
 
8
CodeRank
This code example shows how to use the following methods:format, setTimeZone, applyPattern
                    position.getIndex() == end);
        } 
 
        public void verifyFormatTimezone(String timeZoneId, String expected1,
                String expected2, Date date) {
            format.setTimeZone(SimpleTimeZone.getTimeZone(timeZoneId));
            format.applyPattern("z, zzzz");
            assertEquals("Test z for TimeZone : " + timeZoneId, expected1,
                    format.format(date));
 
            format.applyPattern("Z, ZZZZ");
            assertEquals("Test Z for TimeZone : " + timeZoneId, expected2,
                    format.format(date));
        } 
    } 
 
    /** 
     * java.text.SimpleDateFormat#SimpleDateFormat(java.lang.String, 
     *        java.text.DateFormatSymbols) 
     */ 
8
CodeRank
This code example shows how to use the following methods:format, setTimeZone, applyPattern
                    position.getIndex() == end);
        } 
 
        public void verifyFormatTimezone(String timeZoneId, String expected1,
                String expected2, Date date) {
            format.setTimeZone(SimpleTimeZone.getTimeZone(timeZoneId));
            format.applyPattern("z, zzzz");
            assertEquals("Test z for TimeZone : " + timeZoneId, expected1,
                    format.format(date));
 
            format.applyPattern("Z, ZZZZ");
            assertEquals("Test Z for TimeZone : " + timeZoneId, expected2,
                    format.format(date));
        } 
    } 
 
    /** 
     * java.text.SimpleDateFormat#SimpleDateFormat(java.lang.String, 
     *        java.text.DateFormatSymbols) 
     */ 
8
CodeRank
This code example shows how to use the following methods:setTimeZone
import com.google.common.base.Strings; 
 
public class CommitLogArchiver 
{ 
    private static final Logger logger = LoggerFactory.getLogger(CommitLogArchiver.class); 
    public static final SimpleDateFormat format = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
    static 
    { 
        format.setTimeZone(TimeZone.getTimeZone("GMT"));
    } 
 
    public final Map<String, Future<?>> archivePending = new ConcurrentHashMap<String, Future<?>>();
    public final ExecutorService executor = new JMXEnabledThreadPoolExecutor("commitlog_archiver");
    private final String archiveCommand;
    private final String restoreCommand;
    private final String restoreDirectories;
    public final long restorePointInTime;
    public final TimeUnit precision;
 
    public CommitLogArchiver() 
8
CodeRank
This code example shows how to use the following methods:parse, setLenient, setTimeZone
 
public class Timestamp { 
	private final Date date;
	 
	public static Timestamp createFromDateAndTimeString(String dateAndTime) {
		final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		format.setTimeZone(TimeZone.getTimeZone("GMT"));
		format.setLenient(false);
		try { 
			Timestamp ts = new Timestamp(format.parse(dateAndTime));
			return ts;
		} catch (ParseException e) {
			throw new TorParsingException("Could not parse timestamp string: "+ dateAndTime);
		} 
	} 
	 
	public Timestamp(Date date) {
		this.date = date;
	} 
	 
7
CodeRank
This code example shows how to use the following methods:parse, setTimeZone
        if (s == null)
        { 
            return null; 
        } 
 
        df = new SimpleDateFormat(DATE_TIME_PATTERN);
        if (tz != null)
        { 
            df.setTimeZone(tz);
        } 
        try 
        { 
            return df.parse(s);
        } 
        catch (ParseException e)
        { 
            return null; 
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:format, setTimeZone
	 * @param time 
	 * @return 
	 */ 
	public static String makeHTTPDate(long time) {
		// For HTTP, GMT == UTC 
		SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'",Locale.US);
		sdf.setTimeZone(TZ_UTC);
		return sdf.format(new Date(time));
	} 
	 
// FIXME: For me it returns a parsed time with 2 hours difference, so it seems to parse localtime. WHY? 
	 
//	public static Date parseHTTPDate(String date) throws ParseException { 
//		SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'",Locale.US); 
//		sdf.setTimeZone(TZ_UTC); 
//		return sdf.parse(date); 
//	} 
 
	 
	/** 
7
CodeRank

Related DateFormat setTimeZone Questions & Answers:

setTimeZone Method Overview
Sets the time zone for the calendar of this DateFormat object.
See Code Examples for other Java 8 DateFormat Methods: