ISO8601DateFormat df = new ISO8601DateFormat(); Date d = df.parse("2010-07-28T22:25:51Z");
public void testConversion() { TimeZone.setDefault(TimeZone.getTimeZone("GMT")); String test = "2005-09-16T17:01:03.456+01:00"; String test2 = "1801-09-16T17:01:03.456+01:00"; // convert to a date Date date = ISO8601DateFormat.parse(test); Date date2 = ISO8601DateFormat.parse(test2); // get the string form String strDate = ISO8601DateFormat.format(date); String strDate2 = ISO8601DateFormat.format(date2); // convert back to a date from the converted string Date dateAfter = ISO8601DateFormat.parse(strDate); Date dateAfter2 = ISO8601DateFormat.parse(strDate2); // make sure the date objects match, test this instead of the // string as the string form will be different in different // locales assertEquals(date, dateAfter); assertEquals(date2, dateAfter2); }
private Date getDate(Serializable value) { if(value instanceof Date) { return (Date) value; } else if(value instanceof String) { return ISO8601DateFormat.parse((String) value); } throw new AlfrescoRuntimeException("Parameter 'compareValue' must be of type java.util.Date!"); }
dateObj.put("iso8601", JSONObject.escape(ISO8601DateFormat.format((Date)value))); return dateObj;
if(isDateProperty(propDef) && !ISO8601DateFormat.isTimeComponentDefined(valStr)) return ISO8601DateFormat.parseDayOnly(valStr, TimeZone.getDefault());
/** * Get a calendar object from cache for the system default timezone. * @return calendar object from cache or newly created (if cache is empty) */ public static Calendar getCalendar() { return getCalendar(TimeZone.getDefault()); }
fromDate = ISO8601DateFormat.parseDayOnly(strFromDate, TimeZone.getDefault()); toDate = fromDate;
public void testToZulu(){ String base = "2011-02-04T16:13:14.000"; String zulu = base + "Z"; String utc0 = base + "+00:00"; String utc1 = "2011-02-04T17:13:14" + "+01:00"; String utcMinus1 = "2011-02-04T15:13:14" + "-01:00"; assertEquals(zulu, ISO8601DateFormat.formatToZulu(zulu)); assertEquals(zulu, ISO8601DateFormat.formatToZulu(utc1)); assertEquals(zulu, ISO8601DateFormat.formatToZulu(utc0)); assertEquals(zulu, ISO8601DateFormat.formatToZulu(utcMinus1)); }
public void testTimezones() { TimeZone.setDefault(TimeZone.getTimeZone("GMT")); Date date = null; TimeZone tz = TimeZone.getTimeZone("Australia/Sydney"); String testSydney = "2011-02-04T16:13:14"; String testUTC = "2011-02-04T05:13:14.000Z"; //Sydney date = ISO8601DateFormat.parse(testSydney, tz); assertEquals(testUTC, ISO8601DateFormat.format(date)); // Check with ms too date = ISO8601DateFormat.parse(testSydney + ".000", tz); assertEquals(testUTC, ISO8601DateFormat.format(date)); //Sydney with an offset and timezone date = ISO8601DateFormat.parse(testSydney+"+11:00", tz); assertEquals(testUTC, ISO8601DateFormat.format(date)); // Check with ms too date = ISO8601DateFormat.parse(testSydney + ".000"+"+11:00", tz); assertEquals(testUTC, ISO8601DateFormat.format(date)); }
private Date getDate(Serializable value) { if(value instanceof Date) { return (Date) value; } else if(value instanceof String) { return ISO8601DateFormat.parse((String) value); } throw new AlfrescoRuntimeException("Parameter 'compareValue' must be of type java.util.Date!"); }
private void updateFavouriteNodes(String userName, Type type, Map<PersonFavouriteKey, PersonFavourite> favouriteNodes) { PrefKeys prefKeys = getPrefKeys(type); Map<String, Serializable> preferences = new HashMap<String, Serializable>(1); StringBuilder values = new StringBuilder(); for(PersonFavourite node : favouriteNodes.values()) { NodeRef nodeRef = node.getNodeRef(); values.append(nodeRef.toString()); values.append(","); // ISO8601 string format: PreferenceService works with strings only for dates it seems StringBuilder sb = new StringBuilder(prefKeys.getAlfrescoPrefKey()); sb.append(nodeRef.toString()); sb.append(".createdAt"); String createdAtKey = sb.toString(); Date createdAt = node.getCreatedAt(); if(createdAt != null) { String createdAtStr = ISO8601DateFormat.format(createdAt); preferences.put(createdAtKey, createdAtStr); } } if(values.length() > 1) { values.delete(values.length() - 1, values.length()); } preferences.put(prefKeys.getSharePrefKey(), values.toString()); preferenceService.setPreferences(userName, preferences); }
if(isDateProperty(propDef) && !ISO8601DateFormat.isTimeComponentDefined(valStr)) return ISO8601DateFormat.parseDayOnly(valStr, TimeZone.getDefault());
Calendar calendar = getCalendar(UTC_TIMEZONE); calendar.setTime(isoDate);
fromDate = ISO8601DateFormat.parseDayOnly(strFromDate, TimeZone.getDefault()); toDate = fromDate;
String testCms = "1801-09-16T17:01:03.000Z"; Date dateA = ISO8601DateFormat.parse(testA); Date dateB = ISO8601DateFormat.parse(testB); Date dateC = ISO8601DateFormat.parse(testC); assertEquals(testA, ISO8601DateFormat.format(dateA)); assertEquals(testBms, ISO8601DateFormat.format(dateB)); assertEquals(testCms, ISO8601DateFormat.format(dateC)); String testCms7 = "2005-09-16T17:01:03.1234567+01:00"; Date testCDate = ISO8601DateFormat.parse(testCms3); assertEquals(testCDate, ISO8601DateFormat.parse(testCms4)); assertEquals(testCDate, ISO8601DateFormat.parse(testCms5)); assertEquals(testCDate, ISO8601DateFormat.parse(testCms6)); assertEquals(testCDate, ISO8601DateFormat.parse(testCms7));
if(createdAtStr != null) createdAt = (createdAtStr != null ? ISO8601DateFormat.parse(createdAtStr): null);
private void updateFavouriteNodes(String userName, Type type, Map<PersonFavouriteKey, PersonFavourite> favouriteNodes) { PrefKeys prefKeys = getPrefKeys(type); Map<String, Serializable> preferences = new HashMap<String, Serializable>(1); StringBuilder values = new StringBuilder(); for(PersonFavourite node : favouriteNodes.values()) { NodeRef nodeRef = node.getNodeRef(); values.append(nodeRef.toString()); values.append(","); // ISO8601 string format: PreferenceService works with strings only for dates it seems StringBuilder sb = new StringBuilder(prefKeys.getAlfrescoPrefKey()); sb.append(nodeRef.toString()); sb.append(".createdAt"); String createdAtKey = sb.toString(); Date createdAt = node.getCreatedAt(); if(createdAt != null) { String createdAtStr = ISO8601DateFormat.format(createdAt); preferences.put(createdAtKey, createdAtStr); } } if(values.length() > 1) { values.delete(values.length() - 1, values.length()); } preferences.put(prefKeys.getSharePrefKey(), values.toString()); preferenceService.setPreferences(userName, preferences); }
public static String getFormattedDate(String isoDateTime){ ISO8601DateFormat df = new ISO8601DateFormat(); Date date=new Date(); try { date = df.parse(isoDateTime); } catch (ParseException e) { e.printStackTrace(); } SimpleDateFormat simpleDateFormat=new SimpleDateFormat("hh:mm aaa, EEEE, d-MMM-yyyy"); String dateString=simpleDateFormat.format(date); return dateString; }
public void testGetCalendarMethod() { TimeZone.setDefault(TimeZone.getTimeZone("GMT")); Calendar calendarGMT = ISO8601DateFormat.getCalendar(); TimeZone.setDefault(TimeZone.getTimeZone("BST")); Calendar calendarBST = ISO8601DateFormat.getCalendar(); TimeZone.setDefault(TimeZone.getTimeZone("GMT")); Calendar calendarGMT1 = ISO8601DateFormat.getCalendar(); assertNotSame(calendarGMT, calendarBST); assertSame(calendarGMT, calendarGMT1); }
date = ISO8601DateFormat.parseDayOnly("2012-05-21", tz); date = ISO8601DateFormat.parseDayOnly("2012-05-21T12:13:14Z", tz); cal = Calendar.getInstance(tz); cal.setTime(date); date = ISO8601DateFormat.parseDayOnly("+2012-05-21", tz); cal = Calendar.getInstance(tz); cal.setTime(date); assertEquals(GregorianCalendar.AD, cal.get(Calendar.ERA)); date = ISO8601DateFormat.parseDayOnly("-2012-05-21", tz); cal = Calendar.getInstance(tz); cal.setTime(date); ISO8601DateFormat.parseDayOnly("2011-02-0", tz); fail("Exception expected on illegal format"); try ISO8601DateFormat.parseDayOnly("201a-02-02", tz); fail("Exception expected on illegal format");