0

I'm probably blind to something right in front of me. But In my MVC application, I have an object/model that has a DateTime property.

I do an AJAX GET to retrieve the model. The datetime when received looks something like Date(142342323).

I want to convert this date to the locale setting of the user. In moment.js I don't see a way to set it to local.

I thought about getting the currentculture in MVC and passing that as a value (and storing it as an hidden field on the page ) and then using that for the javascript date format...but there seems to be a discrepancy between c# formats and javascript formats.

Ideas anyone?

I mainly have 1 format for Europe and 1 for US (dd/mm/yyyy and mm/dd/yyyy).

NeedACar
  • 921
  • 2
  • 8
  • 27
  • 1
    it's not clear what you mean here - particularly by "In moment.js I don't see a way to set it to local" - are you talking about "in the local time zone" or "using the local culture"? (It's also really unclear where you're trying to do this formatting - you're talking about both MVC and moment.js, which run on two different systems...) – Jon Skeet Aug 31 '14 at 16:58
  • What have you tried? Can we seem some code? Ideally even a jsfiddle of the issue? – Antiga Aug 31 '14 at 16:58
  • Checkout this section of the docs on i18n support you should find what you need http://momentjs.com/docs/#/i18n/ – Luke Baughan Aug 31 '14 at 16:59
  • I'm not sure simulating the entire flow will work in jsfiddle. Moment.js offers methods to format the date (the ugly AJAX date) to a readable date. It needs a format however, so my initial thinking was I could give it a culture (like en-EN) and it would do the rest. – NeedACar Aug 31 '14 at 17:01
  • 1
    Oke it works thanks to bUKaneer :) I get the currentculture from the backend, and then using moment.locale(culture); to format everything in the front end. – NeedACar Aug 31 '14 at 17:07

0 Answers0