I need to convert the current ISO Date to the required format . How ? Mongodb iso date: 2016-08-31T08:30:17.795Z
required format type: Aug 31,2016 08:30 AM
I need to convert the current ISO Date to the required format . How ? Mongodb iso date: 2016-08-31T08:30:17.795Z
required format type: Aug 31,2016 08:30 AM
I think it is recommended to store date as ISO format into the database. If you want to display on the client side with AngularJS. Just initial a new date object as below.
var date = new Date('2016-08-31T08:30:17.795Z')
It will return as
Wed Aug 31 2016 16:30:17 GMT+0800 (Malay Peninsula Standard Time)
And after that, you can use some built-in function to extract date, time or hour like
date.getDate()
date.getSeconds()
And next time please search on StackOverflow first because there are a lot of answer for this kind of question :D
Refer here for more information.
Date conversion:
parse the date
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
For formatting in your date
DateFormat formatterWithTime = new SimpleDateFormat("MMM dd,YYYY HH:mm a", Locale.ENGLISH);
System.out.println(formatterWithTime.format(formatter.parse("2016-08-31T08:30:17.795Z")));
Output : Aug 31,2016 08:30 AM
Using the mongo java driver, you do not have to supply the date in a given (string-) format. Instead, you simply use java.util.Date objects.