List of utility methods to do Date Now
String | getCurrentTimestampString() Gets the current date and time in a readable format for logging. return SIMPLE_DATE_FORMATTER1.format(new Date()); |
String | getCurrentTimeStr() get Current Time Str Date date = new Date(System.currentTimeMillis()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss-SSS"); String dateStr = sdf.format(date); String[] dateArray = dateStr.split("-"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < dateArray.length; i++) { sb.append(dateArray[i]); return sb.toString(); |
String | getCurrentTimeStr() get Current Time Str Date now = new Date(); DateFormat format = getParseDateFormat(); String result = format.format(now); return result; |
String | getCurrentTimeString(String format) get Current Time String Date cal = new Date(); SimpleDateFormat newSDF = new SimpleDateFormat(format); String timeStr = newSDF.format(cal); return timeStr; |
String | getCurrentTimeString(String pattern) get Current Time String Date now = Calendar.getInstance().getTime(); Format formatter = new SimpleDateFormat(pattern); return formatter.format(now); |
Integer | getCurrentToNextDaySecond() get Current To Next Day Second try { Date current = new Date(Calendar.getInstance().getTime().getTime()); Calendar calendar = Calendar.getInstance(); current.setTime(current.getTime()); calendar.add(Calendar.DATE, 1); SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd"); Date nextDay = simple.parse(simple.format(calendar.getTime())); Long interval = (nextDay.getTime() - current.getTime() - 1) / 1000; ... |
int | getCurrentUnixTime() get Current Unix Time long epoch = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss").parse("01/01/1970 00:00:00").getTime() / 1000; return Integer.parseInt(Long.toString(System.currentTimeMillis() / 1000 - epoch)); |
Date | getCurrentUtcDate() get Current Utc Date SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT); sdf.setTimeZone(TimeZone.getTimeZone(UTC_TIMEZONE_CODE)); String utcTime = sdf.format(new Date()); Date dateToReturn = null; SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT); try { dateToReturn = dateFormat.parse(utcTime); } catch (ParseException e) { ... |
String | getCurrentUTCDate() get Current UTC Date Calendar cal = Calendar.getInstance(); DateFormat df = new SimpleDateFormat(STANDARD_DATE_FORMAT_STRING); df.setTimeZone(TimeZone.getTimeZone("GMT")); return df.format(cal.getTime()); |
int | getCurrentUTCSeconds(Date current) get Current UTC Seconds String dt = stringDateTimeFormat.format(current); String tempDateTime[] = dt.split("-"); int yy = Integer.parseInt(tempDateTime[0]); int MM = Integer.parseInt(tempDateTime[1]); int dd = Integer.parseInt(tempDateTime[2]); int HH = Integer.parseInt(tempDateTime[3]); int mm = Integer.parseInt(tempDateTime[4]); int ss = Integer.parseInt(tempDateTime[5]); ... |