0

I am trying to get my data saved in MongoDb to the user using loading data via AJAX and the format of the datetime in MongoDB is in this format

2017-03-16T14:11:48.700000

How i can display the datetime readable for the user or to display it localized by user location:

1. Option -> 2017-03-16 14:11:48

2. Option -> Mar 16, 2017, 14:11:48 PM

I would to get the second option using javascript.

Thanks

aaa
  • 446
  • 2
  • 8
  • 29
  • 2
    *I would to get the second option using javascript.* And i would get a cup of coffe and a croissant please. *Sarkasm off* What have you tried yet? wich problem are you facing? – Jonas Wilms Apr 15 '17 at 18:17
  • Possible duplicate of [Where can I find documentation on formatting a date in JavaScript?](http://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript) – Dan Green-Leipciger Apr 15 '17 at 20:55

1 Answers1

1

For me, I will use some libs such as momentjs or xdate to solve this(https://momentjs.com/, http://arshaw.com/xdate/)

In other way, you can use native JS to deal with:

var date = new Date('2017-03-16T14:11:48.700000')
date.getMonth()+1  // 3
date.getDate() // 16
date.getFullYear() // 2017
...
Wei
  • 352
  • 1
  • 9
  • 1
    Without using lib, I think you have to implement your function to format your date, and concat string. – Wei Apr 15 '17 at 19:56
  • This is some discussion for related issues, http://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript – Wei Apr 15 '17 at 19:57