0

In my application users can select a culture in their profile, for this example I am testing with the Japanese ("ja") culture.

I use moment.js to generate date time string on the client side but, there are other palces where I generate the date time string on the server with C#.

Using moment.js i use code like this - var now = new moment(); now.format('L') + " " + now.format('LT');

And on the server I set the Thread current culture and then convert it to a string. Thread.CurrentThread.CurrentCulture = myCulture; DateTime.Now.ToString()

These are the results

Moment -

2017/07/10 午後3時57分

C#

2017/07/10 15:57:13

No matter what parameters I try to pass to the ToString method I can't get it producing the same output as the moment client side library. For example passing in "F" produces the following output

2017年7月10日 15:57:13

Is there a simple way to duplicate how moment generates the date time string in .net?

user2945722
  • 1,293
  • 1
  • 16
  • 35
  • Does the machine running the code have all the right language packs installed? – tigerswithguitars Jul 10 '17 at 15:14
  • Momen.js' translations are coming from open contributors. .NET culture formats are no chances to fit them all. I think the better way is convert the datetime to utc or other format without locale string before you pass to backend. It will be much easier to do further data processing. – Kenneth Tsai Jul 10 '17 at 16:15

1 Answers1

0

Run moment.js on Jurrasic and you should get the same output - https://github.com/paulbartrum/jurassic

Ryan Vettese
  • 514
  • 9
  • 22