2

I have UTC date which is one of the properties of a ASP.NET MVC model. I want to convert it in local time to display.

I wrote the conversion logic in C#, bit as the code will run on server, it will take the local time on server. Hence, I will have to convert it in local time on client side i.e. Javascript.

This is my html

<label id="UploadedOn">@item.PublicationDate.ToString("MMMM dd, yyyy,hh:mm: tt")</label>

How can i convert this date to local datetime using javascript..

tereško
  • 58,060
  • 25
  • 98
  • 150
Marcus25
  • 863
  • 1
  • 15
  • 31
  • 5
    Please, stop referring to "ASP.NET MVC" simply as "MVC". One is a framework, while other is a language-independent design pattern. It's like calling IE - "the internet" – tereško Apr 18 '13 at 11:04
  • http://help.dottoro.com/ljlecttk.php – CBroe Apr 18 '13 at 11:32
  • Please see http://stackoverflow.com/questions/6525538/convert-utc-date-time-to-local-date-time-using-javascript or http://stackoverflow.com/questions/15316656/convert-utc-datetime-to-local-datetime – SBirthare Apr 18 '13 at 11:44

1 Answers1

-1

You can create a static method in a utility class which takes the culture as a parameter.

Invoke that method to fetch the culture specific date

public static string FormatDate(string culture)
    {
        string returnDate = string.Empty;

        if (culture == "en-US")
        {
            //format accordingly 
        }
        else if (culture == "en-IN")
        {
            //format accordingly 
        }

        return returnDate;
    }
Moin
  • 166
  • 8