0

I hope you can help me with some JavaScript because I'm a bit lost..

I'm trying to achieve in the easiest way the next format of string for Date object.

var now = new Date();
//how to convert to a pattern like this example: "30/1/2012 20:00:00"  ?

Thanks in advance!

nbanic
  • 1,270
  • 1
  • 8
  • 11
Popokoko
  • 6,413
  • 16
  • 47
  • 58

2 Answers2

1

using the format function in the below link, you can do something like:

var now = new Date();
now.format("dd/mm/yyyy hh:mm:ss");

JavaScript Date Format

tftd
  • 16,203
  • 11
  • 62
  • 106
Akhil
  • 7,570
  • 1
  • 24
  • 23
1

The easy way: http://jsfiddle.net/tftd/UtVnU/

var date = new Date();
//how to convert to a pattern like this example: "30/1/2012 20:00:00"  ?
var time = date.getDay()+"/"+date.getMonth()+"/"+date.getYear()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();

alert(time) /* Outputs 6/2/112 22:16:15 */

You can get everything from the variable date.

tftd
  • 16,203
  • 11
  • 62
  • 106