Java Utililty Methods Date Convert

List of utility methods to do Date Convert

Description

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

Method

CalendarconvertToDateTime(String source)
Code from Axis1 code base Note - We only follow the convention in the latest schema spec
if ((source == null) || source.trim().equals("")) {
    return null;
source = source.trim();
Date date = null;
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.setLenient(false);
...
DateconvertToStartOfDay(Date date)
convert To Start Of Day
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
return cal.getTime();
longconvertTweetDateToLong(String date)

Convert a given date according to a format used by Twitter to long.

if (date == null || (date = date.trim()).length() == 0) {
    throw new IllegalArgumentException("Date must not be null/empty.");
char fc = date.charAt(0);
if (Character.isDigit(fc)) { 
    date = formatTweetDate1(date);
} else { 
    date = formatTweetDate2(date);
...
DateconvertZeroHourDate(Date source)
convert Zero Hour Date
Calendar cal = Calendar.getInstance();
cal.setTime(source);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
CalendardateToCal(Date date)
date To Cal
if (date == null) {
    return null;
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal;
StringdateToEnglishString(java.util.Date date)
date To English String
return dateToEnglishString(date, true, '-', '-');
doubledateToFMDate(Date date)
date To FM Date
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int y = calendar.get(Calendar.YEAR);
int m = calendar.get(Calendar.MONTH);
int d = calendar.get(Calendar.DAY_OF_MONTH);
int datePart = ((y - 1700) * 10000) + ((m + 1) * 100) + d;
return datePart;
intdateToInt(Date date)
date To Int
Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
cal.setTime(date);
return cal.get(Calendar.YEAR) * 10000 + (cal.get(Calendar.MONTH) + 1) * 100 + cal.get(Calendar.DATE);
StringdateToISOXDSb(Date date)
date To ISOXD Sb
if (date == null) {
    return null;
Calendar c = Calendar.getInstance();
c.setTime(date);
int ano = c.get(Calendar.YEAR);
int mes = c.get(Calendar.MONTH) + 1;
int dia = c.get(Calendar.DAY_OF_MONTH);
...
doubledateToJulian(Date date)
date To Julian
Calendar cal = Calendar.getInstance();
cal.set(1858, 10, 17, 0, 0, 0);
double day1 = cal.getTimeInMillis() / 86400000.0;
cal.setTime(date);
double day2 = cal.getTimeInMillis() / 86400000.0;
return (day2 - day1);