Java Utililty Methods Date Format ISO

List of utility methods to do Date Format ISO

Description

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

Method

DateFormatgetISO8601DateFormat(TimeZone tz, String mask)
get ISO Date Format
DateFormat dateFormat = new SimpleDateFormat(mask);
dateFormat.setLenient(false);
dateFormat.setTimeZone(tz);
return dateFormat;
StringgetISO8601DateString(Date d)
get ISO Date String
DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
dfm.setTimeZone(TimeZone.getTimeZone("GMT"));
return dfm.format(d);
StringgetIso8601DateString(long timestampWithMilliseconds)
Format and rounds a given timestamp to a ISO8601-compliant date string
Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTimeInMillis(timestampWithMilliseconds);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.setTimeZone(timeZone);
return getIso8601DateFormat().format(calendar.getTime());
...
SimpleDateFormatgetIso8601DayDateFormat()
get Iso Day Date Format
return new SimpleDateFormat(formatIso8601Day);
DategetISO8601FormatDate(String in)
get ISO Format Date
lock.lock();
try {
    try {
        return getDateFormat().parse(in);
    } catch (ParseException e) {
        throw new RuntimeException("Date failed to parse as ISO 8601: " + in);
} finally {
...
StringgetIso8601String(Date d)
Format a Date into ISO 8601 Complaint format.
SimpleDateFormat sdf = new SimpleDateFormat(ISO_8601_FORMAT);
String result = "";
if (d != null) {
    result = sdf.format(d);
return result;
StringgetISO8601String(Date date)
get ISO String
String result = ISO8601.format(date);
result = result.substring(0, result.length() - 2) + ":" + result.substring(result.length() - 2);
return (result);
StringgetISO8601String(Date date)
get ISO String
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(date);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1;
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
...
StringgetISO8601Time()
Get current moment in ISO 8601 format http://stackoverflow.com/questions/3914404/how-to-get-current-moment-in-iso-8601-format 2016-01-20T10:53:52.457+08:00 2016-01-20T10:53:52.457+0800 2016-01-20T11:11:42.915Z
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
return df.format(new Date());
StringgetISO8601Time(Date date)
get ISO Time
Date nowDate = date;
if (null == date) {
    nowDate = new Date();
SimpleDateFormat df = new SimpleDateFormat(FORMAT_ISO8601);
df.setTimeZone(new SimpleTimeZone(0, TIME_ZONE));
return df.format(nowDate);