android - How to create a valid DateTime object from String -
i have following string.
21-mar-2014
how can convert valid joda datetime object?
i've tried following no joy:
datetimeformatter formatter = datetimeformat.forpattern("d-mmm/y"); datetime dt = formatter.parsedatetime(date);
thanks in advance
matt
a genuine joda answer corrected pattern string , explicit locale
:
string input = "21-mar-2014"; datetimeformatter dtf = datetimeformat.forpattern("dd-mmm-yyyy").withlocale(locale.english); datetime dt = dtf.parsedatetime(input); // using default time zone system.out.println(dt); // 2014-03-21t00:00:00.000+01:00 (my zone: europe/berlin)
if don't need time part (regarding input!) recommend use:
localdate date = dtf.parselocaldate(input);
Comments
Post a Comment