Chris Chris - 3 months ago 17
AngularJS Question

Date formating JSON

I have a JSON object with a date
"timeStarted":"20160809235348+0300"

which in my MySQL database is

2016-08-09 23:53:48
.

I use JPA Eclipselink and JAX-RS to make the REST. In my model this field is:

@Temporal(TemporalType.TIMESTAMP)

@Column(name = "time_started")

private Date timeStarted;


My problem is how to format this date with AngularJS to be like
yyyy-MM-dd HH:mm:ss
.

Answer

you can use momentjs for datetime operations. it is very successful js library.

moment("20160809235348+300","YYYYMMDDhhmmss").format("YYYY-MM-DD HH:mm:ss");