private static String clientDateString() { TimeZone tz = TimeZone.getTimeZone("UTC"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); df.setTimeZone(tz); // strip timezone return df.format(new Date()); }
public final String formatUTCTZ(Date date) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.format(date); }
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); isoFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = isoFormat.parse("2010-05-23T09:01:02");
public String getCurTime() { String fromTimeZone = "GMT+8"; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); format.setTimeZone(TimeZone.getTimeZone(fromTimeZone)); String chinaDate = format.format(date); return chinaDate; }
static String timeAsGmt() { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); sdf.applyPattern("dd MMM yyyy HH:mm:ss z"); return sdf.format(Calendar.getInstance().getTime()); }
private Date newDate(int year, int month, int day, int hour, int offset) { Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT")); calendar.set(year, month - 1, day, hour, 0, 0); calendar.set(Calendar.MILLISECOND, 0); return new Date(calendar.getTimeInMillis() - TimeUnit.HOURS.toMillis(offset)); } }
TimeZone tz = TimeZone.getTimeZone("<local-time-zone>"); //... Date dateValue = rs.getDate("DateColumn"); Calendar calValue = Calendar.getInstance(tz); calValue.setTime(dateValue);
@Override public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { final String dateTimeInUnixFormat = p.getText(); try { Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); calendar.setTimeInMillis(Long.parseLong(dateTimeInUnixFormat + "000")); return calendar.getTime(); } catch (Exception e) { return new Date(0); } } }
@Test public void calendarConversionsDifferingTimeZones() throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HHmmss SSS"); Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC+0")); calendar.setTime(sdf.parse("20180115 153256 001")); }
public void activateOptions() { setDateFormat(dateFormatOption); if(timeZoneID != null && dateFormat != null) { dateFormat.setTimeZone(TimeZone.getTimeZone(timeZoneID)); } }
SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT")); //Local time zone SimpleDateFormat dateFormatLocal = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); //Time in GMT return dateFormatLocal.parse( dateFormatGmt.format(new Date()) );
public static Date stringToDate(String dateString) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.parse(dateString); } catch (ParseException e) { return new Date(0); } }
private SimpleDateFormat createSimpleDateFormat() { SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); fmt.setTimeZone(TimeZone.getTimeZone("GMT+8:00")); return fmt; } }
/** * Generate a date for for the date-header * * @return the server time */ private String getServerTime() { Calendar calendar = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss z", Locale.US ); dateFormat.setTimeZone( TimeZone.getTimeZone( "GMT" ) ); return dateFormat.format( calendar.getTime() ); }
@Parameters(name = "date [{0}], time zone [{1}]") public static List<Object[]> getParameters() { List<Object[]> list = new ArrayList<>(); list.add(new Object[] { new Date(), TimeZone.getTimeZone("PST") }); list.add(new Object[] { new Date(), TimeZone.getTimeZone("CET") }); return list; }
private Calendar getCalendar() { Calendar c = Calendar.getInstance(TimeZone.getTimeZone(time.timezone)); c.set(time.year, time.month, time.monthDay, time.hour, time.minute, time.second); c.set(Calendar.MILLISECOND, 0); return c; } }
SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US); format.setTimeZone(TimeZone.getTimeZone("UTC"));
protected void init() { // Use RFC3339 format for date and datetime. // See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14 this.dateFormat = new RFC3339DateFormat(); // Use UTC as the default time zone. this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); // Set default User-Agent. setUserAgent("Java-SDK"); // Setup authentications (key: authentication name, value: authentication). authentications = new HashMap<String, Authentication>(); authentications.put("api_key", new ApiKeyAuth("header", "api_key")); authentications.put("petstore_auth", new OAuth()); // Prevent the authentications from being modified. authentications = Collections.unmodifiableMap(authentications); }
TimeZone tz = TimeZone.getTimeZone("UTC"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); df.setTimeZone(tz); String nowAsISO = df.format(new Date());
public static Date stringToDate(String dateString) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.parse(dateString); } catch (ParseException e) { return new Date(0); } }