scala - Joda-time parser with instance-local default timezone -


is there "instance-local" version of joda's datetimezone.setdefault? i'm trying achieve this:

val parser = new parserwithdefaulttimezone("gmt+1"); parser.parse("1970-01-01 00:00:00").getmillis // -3600000l parser.parse("1970-01-01 00:00:00 utc").getmillis // 0l 

without polluting global. can find in joda docs (ironically) modifies global state.

if there non-joda solution, interested in that, too.

edit: forgot mention if there no ready-to-use class this, i'll settle for: "what easiest way see if time string contains explicit timezone?" can't distinguish between explicit 1 , timezone joda set default.

edit 2: don't have format string feed; i'm looking infers format @ runtime.

you can use withzone alter date/time zone used:

val fmt = datetimeformat.forpattern("yyyy-mm-dd hh:mm:ss zzz").withzone(datetimezone.forid("europe/berlin")) val date = fmt.parsedatetime(???); 

the set-up required make time zone optional little bit more complicated:

val tz = new datetimeformatterbuilder().appendliteral(" ").appendtimezoneid().toformatter() val fmt = new datetimeformatterbuilder()             .append(datetimeformat.forpattern("yyyy-mm-dd hh:mm:ss"))             .appendoptional(tz.getparser())             .toformatter().withzone(datetimezone.forid("europe/berlin"))  println(fmt.parsedatetime("1970-01-01 12:00:00 utc")) println(fmt.parsedatetime("1970-01-01 12:00:00 europe/berlin")) println(fmt.parsedatetime("1970-01-01 12:00:00")) 

as long remark

i don't have format string feed; i'm looking infers format @ runtime.

applies respect time zone, solution 2 might want. if, on other hand, don't know, in wich format dates provided (dd/mm/yyyy vs. mm/dd/yyyy vs. yyyy/mm/dd vs. whatever), think out of luck: such conversion ambiguous @ best. 01/03/2015 1st of march or 3rd of january?


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -