0

I have a date that I would like to convert to String format. /Date(1281067200000)/ is supposed to be 08/06/2010 12:00:00:00. How do I convert /Date(1281067200000)/ to 8/6/2010?

MrM
  • 21,709
  • 30
  • 113
  • 139
  • If you are following the MVC paradigm then the controller should provide the data to your view in the format needed. The view should be 'dumb'. – Lazarus Aug 11 '10 at 12:47

2 Answers2

1

[UPDATED] Use dateJS:

SO thread

Edit: Try this: http://www.esqsoft.com/javascript_examples/date-to-epoch.htm

Community
  • 1
  • 1
Jarek
  • 5,885
  • 6
  • 41
  • 55
  • This is what I am running into, but the "/Date()/" is messing up my conversion :( – MrM Aug 11 '10 at 14:32
  • I did some testing... var formatDate = new Date(1281067200000) is what I am looking for. Is there a way to use this "/Date(1281067200000)/" and add to make the conversion – MrM Aug 11 '10 at 14:38
  • You can remove unnecessary substrings: var formatDate = new Date("/Date(1281067200000)/".replace("/Date(", "").replace(")/", "")) – Jarek Aug 11 '10 at 14:57
  • I used a substring command then convert to number. Thanks alot for the help. – MrM Aug 11 '10 at 15:19
0

What type of string format? You could use yourDate.toString() or yourDate.toLocaleDateString() depending on your use case.

balupton
  • 47,113
  • 32
  • 131
  • 182
  • My date returns /Date(1281067200000)/ when I would like to have something like 7/30/2010 – MrM Aug 11 '10 at 13:03