0

I have function:

sample(date){
  //operations, for example add one week (7 days) 

  return date;
}

var one = new Date('2012-07-16');
var two = new Date('07/16/2012');

var new = sample(one); // or sample(two)

var day = new.getDate();
var month = new.getMonth();
var year = new.gerYear();

alert(day + month + year);

and now i would like show this date, but how can i check format this date? For example:

alert(sample(one));

should show me date with format 2012-07-23 and if

alert(sample(one));

should show me 07/23/2012

but how can i check format current date? is this possible?

4

1 に答える 1

2

Date objects don't "remember" the format with which they were created - they're just a wrapper for the standard Javascript "milliseconds since the epoch" time values.

You'll need to either roll your own "date to string" functions, or use one of the popular existing libraries (e.g. Datejs)

于 2012-07-16T11:25:48.447 に答える