/*** * Converts this <code>TimeStamp</code> object to a <code>String</code> * of the form: * <blockquote><pre> * EEE, MMM dd yyyy HH:mm:ss.SSS</pre></blockquote> * See java.text.SimpleDataFormat for code descriptions. * * @return a string representation of this date. */ public String toDateString() { if (simpleFormatter == null) { simpleFormatter = new SimpleDateFormat(NTP_DATE_FORMAT, Locale.US); simpleFormatter.setTimeZone(TimeZone.getDefault()); } Date ntpDate = getDate(); return simpleFormatter.format(ntpDate); }
/*** * Converts this <code>TimeStamp</code> object to a <code>String</code> * of the form: * <blockquote><pre> * EEE, MMM dd yyyy HH:mm:ss.SSS UTC</pre></blockquote> * See java.text.SimpleDataFormat for code descriptions. * * @return a string representation of this date in UTC. */ public String toUTCString() { if (utcFormatter == null) { utcFormatter = new SimpleDateFormat(NTP_DATE_FORMAT + " 'UTC'", Locale.US); utcFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); } Date ntpDate = getDate(); return utcFormatter.format(ntpDate); }
/*** * Converts this <code>TimeStamp</code> object to a <code>String</code> * of the form: * <blockquote><pre> * EEE, MMM dd yyyy HH:mm:ss.SSS UTC</pre></blockquote> * See java.text.SimpleDataFormat for code descriptions. * * @return a string representation of this date in UTC. */ public String toUTCString() { DateFormat formatter = null; if (utcFormatter != null) formatter = utcFormatter.get(); if (formatter == null) { // No cache yet, or cached formatter GC'd formatter = new SimpleDateFormat(NTP_DATE_FORMAT + " 'UTC'", Locale.US); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); utcFormatter = new SoftReference<DateFormat>(formatter); } Date ntpDate = getDate(); synchronized (formatter) { return formatter.format(ntpDate); } }
/*** * Converts this <code>TimeStamp</code> object to a <code>String</code> * of the form: * <blockquote><pre> * EEE, MMM dd yyyy HH:mm:ss.SSS UTC</pre></blockquote> * See java.text.SimpleDataFormat for code descriptions. * * @return a string representation of this date in UTC. */ public String toUTCString() { DateFormat formatter = null; if (utcFormatter != null) formatter = (DateFormat) utcFormatter.get(); if (formatter == null) { // No cache yet, or cached formatter GC'd formatter = new SimpleDateFormat(NTP_DATE_FORMAT + " 'UTC'", Locale.US); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); utcFormatter = new SoftReference(formatter); } Date ntpDate = getDate(); synchronized (formatter) { return formatter.format(ntpDate); } }
/*** * Converts this <code>TimeStamp</code> object to a <code>String</code> * of the form: * <blockquote><pre> * EEE, MMM dd yyyy HH:mm:ss.SSS</pre></blockquote> * See java.text.SimpleDataFormat for code descriptions. * * @return a string representation of this date. */ public String toDateString() { DateFormat formatter = null; if (simpleFormatter != null) { formatter = (DateFormat) simpleFormatter.get(); } if (formatter == null) { // No cache yet, or cached formatter GC'd formatter = new SimpleDateFormat(NTP_DATE_FORMAT, Locale.US); formatter.setTimeZone(TimeZone.getDefault()); simpleFormatter = new SoftReference(formatter); } Date ntpDate = getDate(); synchronized (formatter) { return formatter.format(ntpDate); } }
/*** * Converts this <code>TimeStamp</code> object to a <code>String</code> * of the form: * <blockquote><pre> * EEE, MMM dd yyyy HH:mm:ss.SSS</pre></blockquote> * See java.text.SimpleDataFormat for code descriptions. * * @return a string representation of this date. */ public String toDateString() { DateFormat formatter = null; if (simpleFormatter != null) { formatter = simpleFormatter.get(); } if (formatter == null) { // No cache yet, or cached formatter GC'd formatter = new SimpleDateFormat(NTP_DATE_FORMAT, Locale.US); formatter.setTimeZone(TimeZone.getDefault()); simpleFormatter = new SoftReference<DateFormat>(formatter); } Date ntpDate = getDate(); synchronized (formatter) { return formatter.format(ntpDate); } }
@Override public Long getSerializableComparable() { return TimeStamp.getNtpTime(timestamp()).getDate().getTime(); } }
@Test public void initialTimestamp() { HybridTimestamp timestamp = new HybridTimestamp(physicalTimeProvider); TimeStamp ntpTime = new TimeStamp(timestamp.getLogicalTime()); assertEquals(ntpTime.getDate(), new Date(0)); }