Here you can find the source of getCurrDateTime()
public static Date getCurrDateTime()
//package com.java2s; //License from project: Apache License import java.text.ParsePosition; import java.text.SimpleDateFormat; public class Main { public static Date getCurrDateTime() { return stringToDate(getCurrTime()); // return new Date(System.currentTimeMillis()); }/*from w w w . ja v a2 s . co m*/ public static Date stringToDate(String dateString) { String sf = "yyyy-MM-dd HH:mm:ss"; Date dt = stringToDate(dateString, sf); return dt; } public static Date stringToDate(String dateString, String sf) { ParsePosition pos = new ParsePosition(0); SimpleDateFormat sdf = new SimpleDateFormat(sf); Date dt = sdf.parse(dateString, pos); return dt; } public static String getCurrTime() { Date date_time = new Date(); return FormatDate(date_time, "yyyy-MM-dd HH:mm:ss"); } public static String FormatDate(Date date, String sf) { if (date == null) return ""; SimpleDateFormat dateformat = new SimpleDateFormat(sf); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); if (date.getHours() == 0) return sdf.format(date); else return dateformat.format(date); } }