Java Utililty Methods Date UTC Parse

List of utility methods to do Date UTC Parse

Description

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

Method

DategetUTCDate(int year, int month, int day)
get UTC Date
return getUTCDate(year, month, day, 0, 0, 0);
DategetUTCMidnightZero(Date d)
get UTC Midnight Zero
Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getTimeZone("GMT-0"));
cal.setTime(d);
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();
...
DateparseDateAsUTC(String dateString)
Attempt to parse the given string of form: yyyy-MM-dd[THH:mm:ss[.SSS][Z]] as a Date.
if (dateString == null || dateString.length() == 0) {
    return null;
SimpleDateFormat formatter = new SimpleDateFormat();
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
int length = dateString.length();
if (dateString.startsWith("-")) {
    length--;
...
DateparsePartialUTCToDate(String utcDate)
parse Partial UTC To Date
if (utcDate.length() == 4) {
    DateTime dateTime = utcYFormatter.parseDateTime(utcDate);
    return dateTime.toDate();
if (utcDate.length() == 10) {
    DateTime dateTime = utcYMDFormatter.parseDateTime(utcDate);
    return dateTime.toDate();
if (utcDate.length() == 19) {
    DateTime dateTime = utcYMDHMSFormatter.parseDateTime(utcDate);
    return dateTime.toDate();
DateTime dateTime = utcFormatter.parseDateTime(utcDate);
return dateTime.toDate();
DateparseToUTCDate(String timestamp, String pattern)
Format.
DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
fmt = fmt.withZoneUTC();
Date date = fmt.parseDateTime(timestamp).toDate();
return date;
StringparseUTCDateToString(Date date)
parse UTC Date To String
return dateToString(date);
DateparseUTCToDate(String utcDate)
parse UTC To Date
DateTime dateTime = utcFormatter.parseDateTime(utcDate);
return dateTime.toDate();
DatetoUTC(Date date)
Convert the specified date from local time zone to UTC time zone.
Calendar cal = new GregorianCalendar(TimeZone.getDefault());
cal.setTime(date);
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
return cal.getTime();
DatetoUTC(Date date)
to UTC
if (date == null) {
    return null;
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
return cal.getTime();
DatetoUTC(Date date)
Extract date and time from the given date and returns a date object with the same date/time on the UTC time zone.
Calendar cal = Calendar.getInstance();
cal.setTime(date);
Calendar utcCal = Calendar.getInstance();
utcCal.setTimeZone(TimeZone.getTimeZone("UTC"));
utcCal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH),
        cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
utcCal.set(Calendar.MILLISECOND, cal.get(Calendar.MILLISECOND));
return utcCal.getTime();
...