List of utility methods to do Unix Date
long | toUnixTime(Date date) to Unix Time return date.getTime() / 1000;
|
long | toUnixTime(SimpleDateFormat simpleDateFormat, String audioboxDate) Given a string representing an UTC date provided by AudioBox server, this method returns a unix timestamp (always in UTC). simpleDateFormat.applyPattern(AUDIOBOX_DATE_FORMAT); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = simpleDateFormat.parse(audioboxDate); return date.getTime(); |
long | unixTime() unix Time java.util.Calendar cal1 = new GregorianCalendar(1970, 0, 1, 0, 0, 0); java.util.Calendar cal = java.util.Calendar.getInstance(java.util.Locale.CHINA); int zoneOffset = cal.get(java.util.Calendar.ZONE_OFFSET); int dstOffset = cal.get(java.util.Calendar.DST_OFFSET); cal.add(java.util.Calendar.MILLISECOND, -(zoneOffset + dstOffset)); long now = cal1.getTimeInMillis() / 1000; long now1 = cal.getTimeInMillis() / 1000; return now1 - now; ... |
Date | unixTimeToDate(long unixTime) unix Time To Date Date date = new Date(unixTime * 1000L); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); String formattedDate = sdf.format(date); System.out.println(formattedDate); return date; |
Integer | unixTimeToDateInt(long unixTime) unix Time To Date Int return Integer.parseInt(new SimpleDateFormat("yyyyMMdd").format(new Date(unixTime))); |
String | unixTimeToString(int time) unix Time To String long timeMs = time * 1000L; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); format.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = new Date(timeMs); return format.format(date); |