0

I need to convert the string date format from Fri Feb 20 11:13:43 GMT 2015 to 2015/20/02 11:12

I used

var dateTest = new Date("Fri Feb 20 11:13:43 GMT 2015");
var yr = dateTest.getYear();

but yr seems to return "115"

1

3 Answers 3

3

Use

var yr = DateTest.getFullYear();
Sign up to request clarification or add additional context in comments.

4 Comments

this is right but it returns 1 for getMonth(), 5 for getDay()
For month increment it by one and use getDate() instead of getDay(). getDay() will return day of week.
@MelSyGallosa As expected, getMonth() returns the 0-based month and getDay() returns the 0-based day of week - review Date
thank you! to get the format that I wanted. I used dateTest.getFullYear() + "/" + dateTest.getMonth()+1 + "/" + dateTest.getDate + " " + dateTest.getUTCHours() + ":" +dateTest.getUTCMinutes()
1

You want to use

var yr = dateTest.getFullYear();

Comments

0

Try This, Its Return full date and you can also change its format as you want

For Return Year

var d = new Date();
alert(d.getFullYear());

Return Full Date

  var d = new Date();

  var month = d.getMonth() + 1;
  var day = d.getDate();

  var output = (day < 10 ? '0' : '') + day + '/' +
  (month < 10 ? '0' : '') + month + '/' +
  d.getFullYear();

  alert(output);

Here is Fiddle

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.