0

I develop a application with node.js and mongodb.

I think the question is also available in javascript. How can I convert the date format to the way I want,

like yyyy/mm/dd/hh/mm/ss?

hh54188
  • 14,887
  • 32
  • 113
  • 184
  • That syntax for a date makes no sense, however the best way is within your JavaScript using its date functions – Sammaye Jan 01 '13 at 13:54
  • Did you ever google for "javascript parse date string"? –  Jan 01 '13 at 14:27

2 Answers2

0
> var a = new Date()
> a
ISODate("2013-01-01T13:50:36.839Z")
> a.getFullYear() + "/" + (a.getMonth() + 1) + "/" + a.getDate() + "/" + a.getHours() + "/" + a.getMinutes() + "/" + a.getSeconds()
2013/1/1/16/50/36

The code can be improved with string formatting methods. Also, take look at this.

Community
  • 1
  • 1
madhead
  • 31,729
  • 16
  • 153
  • 201
0

yearMonthDay: { $dateToString: { format: "%Y-%m-%d-%H-%M", date: {$subtract:["$cdt",14400000]}}}

This is how you can get all different formats dateformat

Jin Thakur
  • 2,711
  • 18
  • 15