android - Java Convert military hour to civilian hour with Joda time -
i'm trying convert int (which represents military time hour) , convert civilian time. example if have hour "13" want convert "1:00 pm". here's i've been attempting:
private datetimeformatter hourformat = datetimeformat.forpattern("hh:mm a"); private datetimeformatter dateformat = datetimeformat.forpattern("yyyy-mm-dd"); int hour = 8; datetime fulldate = new datetime(); string date = dateformat.print(fulldate) + " " + integer.tostring(hour) + ":00"; string civiliantime = hourformat.parsedatetime(date).tostring();
logcat:
java.lang.illegalargumentexception: invalid format: "2016-01-27 8:00" malformed @ "16-01-27 8:00" @ org.joda.time.format.datetimeformatter.parsedatetime(datetimeformatter.java:945)
joda doesn't allow me reformat hour, "8:00 short" type of error why included date , combined date , time 1 string though don't need date. have tried using time zone component in there same error. background: int "hour" comes timestamps (utc w/ timezone offset) database query spits out list of hours need. hours have taken timezone account.
in essence i'm trying go "hh" hour of day (0-23) "hh:mm a" clockhour of halfday (1-12). i'm assuming "hh" "h" because leading 0 dropped when going database query application. i've tried hour = 8 , hour = 10 same resulting error.
thanks 1 of comments use localtime
, gets done:
private datetimeformatter hourformat = datetimeformat.forpattern("h:mm a"); int hour = 8; string ltime = new localtime(hour,0).tostring(hourformat);
in format pattern, datetimeformat
class of joda-time says use:
h
(lowercase) clockhour of halfday (1~12)h
(uppercase) hour of day (0~23)
use double hh
if want pad leading 0
(zero) single digit values. example 08:00
rather 8:00
. when parsing, number of digits accepted.
Comments
Post a Comment