datetime - Display Java 8 Time api in this format "HH:mma" (05:53PM) and add set Time with only minutes -
i want display / print out time 02:15pm
, able set time based on minutes(possibly larger 59).
this doesn't seem work:
datetimeformatter formatter = datetimeformatter.ofpattern("hh:mma"); string text = time.format(formatter); localtime parsedtime = localtime.parse(text, formatter);
it shows time 16:15
wrong 12/24 format(and am/pm missing of course)
so far set time this:
void settime(int minutes) { time = localtime.of(minutes / 60, minutes % 60); }
is there way in more elegant way (read: without dividing)?
i not want use joda time.
as discussed, use hh
instead of hh
am/pm clock. list of patterns detailed in the javadoc. example:
localtime time = localtime.of(18, 0); datetimeformatter fmt = datetimeformatter.ofpattern("hh:mma"); system.out.println(fmt.format(time)); //06:00pm
as creating time number of minutes, can use:
localtime.midnight.plusminutes(minutes);
Comments
Post a Comment