How to use intl DateFormat to convert string "1030" to "10:30am"

367 Views Asked by At

I am dealing with time strings such as "1030" or "0230"

I am trying:

var time = "1030";
DateFormat.jm().format(DateFormat("hhmm").parse(time));

However that throws the following error:

Unhandled Exception: FormatException: Trying to read mm from 1030 at position 4

What am I doing wrong?

Edit: Nvm, I guess I have to substring the time into "hour:min" and use "hh:mm", then it works. So, convert the time "1030" to "10:30", and then use "hh:mm"..

1

There are 1 best solutions below

1
On

use

HH:mm

var time = "10:30";
DateFormat.jm().format(DateFormat("HH:mm").parse(time));