Java Utililty Methods Date Now

List of utility methods to do Date Now

Description

The list of methods to do Date Now are organized into topic(s).

Method

BigDecimalgetCurrentTimeAsNumber()
get Current Time As Number
String returnStr = null;
SimpleDateFormat f = new SimpleDateFormat("yyyyMMddHHmmss");
Date date = new Date();
returnStr = f.format(date);
return new BigDecimal(returnStr);
StringgetCurrentTimeAsString()
Get current Time.
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
int millisecond = calendar.get(Calendar.MILLISECOND);
String mDateFormat = "";
DecimalFormat twoDigitFormat = new DecimalFormat("00");
mDateFormat = twoDigitFormat.format(hour) + twoDigitFormat.format(minute) + twoDigitFormat.format(second)
...
StringgetCurrentTimeForFileName()
get Current Time For File Name
SimpleDateFormat formatter = new SimpleDateFormat("ddMMyyyy_HHmmssS");
Date timeStr = Calendar.getInstance().getTime();
return formatter.format(timeStr);
StringgetCurrentTimeForLog()
Get current time string in format mm-dd-yy 5:31:31 PM
return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, Locale.US).format(new Date())
        .replaceAll("/", "-");
StringgetCurrentTimeForName()
Gets current date (for random name of new item)
SimpleDateFormat f = new SimpleDateFormat("yyMMddHHmmss_");
return f.format(Calendar.getInstance().getTime());
StringgetCurrentTimeForUseInAFileName()
get Current Time For Use In A File Name
String time = DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
time = time.replaceAll(":", "_");
time = time.replaceAll(",", "");
return time;
StringgetCurrentTimeInMySqlTime()
get Current Time In My Sql Time
SimpleDateFormat sdf = new SimpleDateFormat(_16DIGIT_DATE_TIME_MYSQL);
return sdf.format(new Date());
StringgetCurrentTimeInMySqlTime()
get Current Time In My Sql Time
SimpleDateFormat sdf = new SimpleDateFormat(_16DIGIT_DATE_TIME_MYSQL);
return sdf.format(getTimezoneDate(_DEFAULT_TIMEZON));
StringgetCurrentTimeInString(SimpleDateFormat dateFormat)
get current time in milliseconds
return getTime(getCurrentTimeInLong(), dateFormat);
StringgetCurrentTimeInString(String format)
get Current Time In String
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(date);