diff options
author | Richard Maudsley <richard.maudsley@isode.com> | 2014-03-11 11:14:25 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2014-05-26 17:16:33 (GMT) |
commit | db8568aa6a9bbfa8dca9cdae696e8428a0068d89 (patch) | |
tree | 38ab6981542192128711049cb551dc03cf6f97a7 /src/com/isode/stroke/base/DateTime.java | |
parent | cafd510a0efc9df985999ceded57efa1d411de2e (diff) | |
download | stroke-db8568aa6a9bbfa8dca9cdae696e8428a0068d89.zip stroke-db8568aa6a9bbfa8dca9cdae696e8428a0068d89.tar.bz2 |
Added MAM parsers, serializers and tests.
Change-Id: I4e5368f9ac86446b7ebf976e2cb63d64ebefe7b2
Diffstat (limited to 'src/com/isode/stroke/base/DateTime.java')
-rw-r--r-- | src/com/isode/stroke/base/DateTime.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/com/isode/stroke/base/DateTime.java b/src/com/isode/stroke/base/DateTime.java new file mode 100644 index 0000000..27c85d8 --- /dev/null +++ b/src/com/isode/stroke/base/DateTime.java @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.base; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; + +public class DateTime { + public static Date stringToDate(String date) { + SimpleDateFormat parser = new SimpleDateFormat(format); + parser.setTimeZone(TimeZone.getTimeZone("UTC")); + try { + return parser.parse(date); + } catch (ParseException e) { + return null; + } + } + + public static String dateToString(Date date) { + SimpleDateFormat parser = new SimpleDateFormat(format); + parser.setTimeZone(TimeZone.getTimeZone("UTC")); + return parser.format(date); + } + + static private String format = "yyyy-MM-dd'T'HH:mm:ss'Z'"; +} |