public MavenBuildTimestamp( Date time, String timestampFormat ) { if ( timestampFormat == null ) { timestampFormat = DEFAULT_BUILD_TIMESTAMP_FORMAT; } if ( time == null ) { time = new Date(); } SimpleDateFormat dateFormat = new SimpleDateFormat( timestampFormat ); dateFormat.setCalendar( new GregorianCalendar() ); dateFormat.setTimeZone( DEFAULT_BUILD_TIME_ZONE ); formattedTimestamp = dateFormat.format( time ); }
@Override public void serialize(final Object obj, final StringBuilder buf) { Date d = (Date) obj; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT"))); serializer.serialize(new BasicDBObject("$date", format.format(d)), buf); }
@Override public String format(String value) { if (!StringUtils.hasText(value)) { return null; } Calendar calendar = DateUtils.parseDate(value); dateFormat.setCalendar(calendar); return dateFormat.format(calendar.getTime()); } }
} else { SimpleDateFormat format = new SimpleDateFormat(_msDateFormat); format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT"))); o = format.parse(b.get("$date").toString(), new ParsePosition(0)); format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT"))); o = format.parse(b.get("$date").toString(), new ParsePosition(0));
@Override public String convertToString(Object object) { if (object instanceof GregorianCalendar == false) { throw new RuntimeException("Unable to convert calendar as it is not a GregorianCalendar"); } GregorianCalendar cal = (GregorianCalendar) object; SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); f.setCalendar(cal); String str = f.format(cal.getTime()); return str.substring(0, 26) + ":" + str.substring(26) + "[" + cal.getTimeZone().getID() + "]"; } @Override
@Override public Object convertFromString(Class<?> cls, String str) { if (str.length() < 31 || str.charAt(26) != ':' || str.charAt(29) != '[' || str.charAt(str.length() - 1) != ']') { throw new IllegalArgumentException("Unable to parse date: " + str); } TimeZone zone = TimeZone.getTimeZone(str.substring(30, str.length() - 1)); String str2 = str.substring(0, 26) + str.substring(27, 29); SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); GregorianCalendar cal = new GregorianCalendar(zone); cal.setTimeInMillis(0); f.setCalendar(cal); try { f.parseObject(str2); return f.getCalendar(); } catch (ParseException ex) { throw new RuntimeException(ex); } } },
private static GregorianCalendar parseSimpleDate(String text, String[] fmts, ParsePosition initialWhere) { for(String fmt : fmts) { ParsePosition where = new ParsePosition(initialWhere.getIndex()); SimpleDateFormat sdf = new SimpleDateFormat(fmt, Locale.ENGLISH); GregorianCalendar retCal = newGreg(); sdf.setCalendar(retCal); if (sdf.parse(text, where) != null) { initialWhere.setIndex(where.getIndex()); skipOptionals(text, initialWhere, " "); return retCal; } } return null; }
public RouterKeyGenerator(I2PAppContext context) { _log = context.logManager().getLog(RoutingKeyGenerator.class); _context = context; // make sure GMT is set, azi2phelper Vuze plugin is disabling static JVM TZ setting in Router.java _fmt.setCalendar(_cal); // ensure non-null mod data generateDateBasedModData(); }
private DateFormat getRequestDateParser() { SimpleDateFormat dateParser = new SimpleDateFormat(REQUEST_DATE_FORMAT); Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); dateParser.setCalendar(calendar); return dateParser; }
public DateTime(String dateString, String format) throws ParseException { this(Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.getDefault()), Locale.getDefault()); SimpleDateFormat dateFormat = new SimpleDateFormat(format); dateFormat.setCalendar(this.calendar); dateFormat.parse(dateString); }
public DateTime(String dateString, String format) throws ParseException { this(Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.getDefault()), Locale.getDefault()); SimpleDateFormat dateFormat = new SimpleDateFormat(format); dateFormat.setCalendar(this.calendar); dateFormat.parse(dateString); }
@Override public void serialize(final Object obj, final StringBuilder buf) { Date d = (Date) obj; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT"))); serializer.serialize(new BasicDBObject("$date", format.format(d)), buf); }
public Timestamp getTimestamp(final Calendar cal) throws ParseException { if (rawBytes == null) { return null; } final String rawValue = getString(); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setCalendar(cal); final java.util.Date utilTime = sdf.parse(rawValue); return new Timestamp(utilTime.getTime()); }
private static SimpleDateFormat createTimestampFormat() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH); GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); // We use Proleptic Gregorian Calendar (i.e., Gregorian calendar extends // backwards to year one) for timestamp formating. calendar.setGregorianChange(new Date(Long.MIN_VALUE)); sdf.setCalendar(calendar); return sdf; }
@Override protected void serialize(Object obj, Writer writer, OutputStream out) throws IOException { Date d = (Date) obj; SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); format.setCalendar(new GregorianCalendar( new SimpleTimeZone(0, "GMT"))); JSON.serialize(serializer, new BasicDBObject("$date", format.format(d)), writer, out); }
private static SimpleDateFormat createTimestampFormat() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH); GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); // We use Proleptic Gregorian Calendar (i.e., Gregorian calendar extends // backwards to year one) for timestamp formating. calendar.setGregorianChange(new Date(Long.MIN_VALUE)); sdf.setCalendar(calendar); return sdf; }
private static SimpleDateFormat createTimestampFormat() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH); GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); // We use Proleptic Gregorian Calendar (i.e., Gregorian calendar extends // backwards to year one) for timestamp formating. calendar.setGregorianChange(new Date(Long.MIN_VALUE)); sdf.setCalendar(calendar); return sdf; }
@Override public String format(String value) { if (!StringUtils.hasText(value)) { return null; } Calendar calendar = DateUtils.parseDate(value); dateFormat.setCalendar(calendar); return dateFormat.format(calendar.getTime()); } }
@Override public String format(String value) { if (!StringUtils.hasText(value)) { return null; } Calendar calendar = DateUtils.parseDate(value); dateFormat.setCalendar(calendar); return dateFormat.format(calendar.getTime()); } }
private void initFormats() { mDayOfWeekFormat = new SimpleDateFormat("EEEE", Locale.getDefault()); mDayOfWeekFormat.setCalendar(mCalendar); mDateFormat = DateFormat.getDateFormat(DigitalWatchFaceService.this); mDateFormat.setCalendar(mCalendar); }