1

I have a date string which looks like this: 2013-04-06T14:15:00 I'm looking for functions similar to toLocaleDateString() (documentation). However, those functions don't take a String parameter; you need to create a Date object first. I'm trying to avoid timezones altogether, so does anyone know of a function (standard or from a plugin) which can format a datestring using a specific locale's rules (1/17/2013 vs 17/1/2013 etc.) using only my datestring?

I'm currently using jQuery, and this plugin for formatting dates: jQuery.dateFormat

6
  • Would be better to format it correctly at the source. Any reason why this can't be done? Where are you getting the string data from? Commented Jan 17, 2013 at 18:57
  • this date string is returned from a server Commented Jan 17, 2013 at 19:02
  • Whats wrong with new Date("1/17/2013")? Commented Jan 17, 2013 at 19:04
  • or new Date("2013-04-06T14:15:00") Commented Jan 17, 2013 at 19:05
  • @RoddyPiper: Do you control the server code, because it would be better to return the string in the local format. You can get the browsers local preferences from the Request data, and use that to determine the format Commented Jan 17, 2013 at 19:07

1 Answer 1

1

Pass your date string to the Date constructor. It parses most legitimate formats.

new Date("1/17/2013")
new Date("2013-04-06T14:15:00")
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for forcing me to paste the output and look at it further, I realize its going to be sufficient as long as I convert the date object back to GMT

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.