0

I want to convert the datetime format according to the culture through javaScript/jQuery.

Ex: Let we have a date:

var starDate = "7/4/2013 9:00:00 AM"

then after conversion this into french it should be "4 juillet 2013 09:00"

like we have in c#:

DateTime dteStartTime = "7/4/2013 9:00:00 AM";
dteStartTime.ToString("f", CultureInfo.CreateSpecificCulture("fr-CA"));

it will convert this datetime into "4 juillet 2013 09:00"

mati
  • 5,218
  • 3
  • 32
  • 49
dIvYaNsH sInGh
  • 1,943
  • 3
  • 21
  • 40

2 Answers2

4

Working with dates in JavaScript without a helper library is very painful and error prone. Have you tried using Moment.js? It has support for many languages including French (Canada).

Cymen
  • 14,079
  • 4
  • 52
  • 72
  • is this work with your browser locale? I need something where I put the locale like in my example above in c#. – dIvYaNsH sInGh Sep 09 '13 at 19:03
  • @dIvYaNsHsInGh You need to pass along your language string and use it in Moment.js to convert a date to the language you want. Look at the `.lang()` method in Moment.js. – Cymen Sep 09 '13 at 19:10
0

You can do this by using the globalize.js. Just make sure you pass a correct culture code. Maybe it will better idea just to pass the converted date from C# as string?

Daemon025
  • 87
  • 1
  • 11
  • Agreed -- if it isn't going to change, it makes more sense to have the view on the server side take care of it. I was assuming it would change via JavaScript on the client side. – Cymen Sep 09 '13 at 19:11