Java Utililty Methods Long Number to Timestamp

List of utility methods to do Long Number to Timestamp

Description

The list of methods to do Long Number to Timestamp are organized into topic(s).

Method

Stringtimestamp2DataTime(long timestamp)
timestamp Data Time
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(Long.valueOf(timestamp));
Datetimestamp2Date(long timestamp, String timezone)
timestamp Date
SimpleDateFormat dateFormatGmt = new SimpleDateFormat(DATE_FORMAT);
dateFormatGmt.setTimeZone(TimeZone.getTimeZone(timezone));
SimpleDateFormat dateFormatLocal = new SimpleDateFormat(DATE_FORMAT);
return dateFormatLocal.parse(dateFormatGmt.format(new Date(timestamp)));
Stringtimestamp2DateTime(long t)
convert a Unix timestamp to date time string
String ret;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
ret = sdf.format(t);
return ret;
StringtimestampToHumanDateAndTime(long timestamp)
Convert a timestamp to a humanly readable date and time.
return m_dateAndTime.get().format(new Date(timestamp));
StringtimestampToString(long micros)
Transforms a timestamp into a string, whose formatting and timezone is consistent across Kudu.
long tsMillis = micros / 1000L;
long tsMicros = micros % 1000000L;
String tsStr = DATE_FORMAT.get().format(new Date(tsMillis));
return String.format("%s.%06dZ", tsStr, tsMicros);
StringtimestampToString(long time)
timestamp To String
return time != -1 ? "until " + formatTimestamp(time) : "forever";
StringtimestampToString(long timestamp)
Convert a timestamp in a readable format for a human in the format : YYYY/mm/dd HH:mm:ss
Calendar cal = GregorianCalendar.getInstance();
timestamp *= 1000;
cal.setTimeInMillis(timestamp);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
return cal.get(GregorianCalendar.YEAR) + "-" + (cal.get(GregorianCalendar.MONTH) + 1) + "-"
        + cal.get(GregorianCalendar.DAY_OF_MONTH) + " " + sdf.format(cal.getTime());
StringtimeString(long timestamp)
time String
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.getDefault()).format(new Date(timestamp));
StringtoDateTimeString(long timestamp)
Converts a timestamp to string yyyy-mm-dd hh:mm:ss
String DATE_FORMAT = "yyyy-MM-dd";
String TIME_FORMAT = "HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
SimpleDateFormat stf = new SimpleDateFormat(TIME_FORMAT);
return sdf.format(new Date(timestamp)) + "T" + stf.format(new Date(timestamp));
StringtoSolrTimestamp(Long epoch)
to Solr Timestamp
SimpleDateFormat out = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
return out.format(epoch);