Search code examples
asp.netdatetimelocalizationwebmethod

why datetime is not localized in asp.net webmethod?


i've something like that

[WebMethod]
public static string web_method()
{
    return getDate();
}

public static string getDate()
{
    return DateTime.Now.ToString("dddd, MMMM dd, yyyy");
}

the getDate method is call with page_load() and if the culture Arabic it returns the month name and day name translated, if it's called with the web_method the date is not translated.

help plz, thanks :)


Solution

  • Have you tried the following?

      // Creates a CultureInfo for Jordan.
      CultureInfo ci = new CultureInfo("ar-JO");
    
      // Displays dt, formatted using the ShortDatePattern
      // and the CultureInfo.
    
      return DateTime.Now.ToString("dddd, MMMM dd, yyyy", ci);
    

    Might help