Java Utililty Methods Unix time

List of utility methods to do Unix time

Description

The list of methods to do Unix time are organized into topic(s).

Method

DategetUnixEpochDateTime()
Returns the starting Unix Epoch Time.
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.set(1970, 0, 1, 0, 0, 0);
return calendar.getTime();
longgetUnixTime(Date date)
get Unix Time
Calendar instance = Calendar.getInstance();
instance.setTime(date);
long utc = Date.UTC(instance.get(Calendar.YEAR) - 1900, instance.get(Calendar.MONTH),
        instance.get(Calendar.DAY_OF_MONTH), instance.get(Calendar.HOUR_OF_DAY),
        instance.get(Calendar.MINUTE), instance.get(Calendar.SECOND));
return utc;
intgetUnixTimeByDate(Date date)
get Unix Time By Date
return (int) (date.getTime() / 1000L);
intunix2afpTime(long ut)
unixafp Time
int ret = (int) ((ut - timeOffset) / 1000);
return ret;
StringunixDateToString(int date)
Helper for CAST({date} AS VARCHAR(n)).
final StringBuilder buf = new StringBuilder(10);
unixDateToString(buf, date);
return buf.toString();
intunixTime()
unix Time
return (int) (System.currentTimeMillis() / 1000);
longunixtime()
Calculates "unix time", ie seconds after 1970
return System.currentTimeMillis() / 1000L;
longunixTimestamp(int year, int month, int day, int hour, int minute, int second)
unix Timestamp
final int date = ymdToUnixDate(year, month, day);
return (long) date * MILLIS_PER_DAY + (long) hour * MILLIS_PER_HOUR + (long) minute * MILLIS_PER_MINUTE
        + (long) second * MILLIS_PER_SECOND;
StringunixTimestampToString(long timestamp)
Helper for CAST({timestamp} AS VARCHAR(n)).
final StringBuilder buf = new StringBuilder(17);
int date = (int) (timestamp / MILLIS_PER_DAY);
int time = (int) (timestamp % MILLIS_PER_DAY);
if (time < 0) {
    --date;
    time += MILLIS_PER_DAY;
unixDateToString(buf, date);
...
DateunixtimeToDate(long time)
Converts a unix time stamp to a Date
Calendar c = Calendar.getInstance();
c.setTimeInMillis(time * 1000);
return c.getTime();