0

I have below code in web.config.

<globalization requestEncoding="euc-kr" responseEncoding="euc-kr" culture="ko-KR" uiCulture="ko-KR" />

And I am using below code to return string and send to UI using webapi.

return string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);

And In my local server output is correct , 2020-07-02 10:24:33

But when I push code in to korea server (Korea OS) then output is coming as 2020-07-02 10:24 오전.

May I know below code will work to return output like this 2020-07-02 10:24:33 even in korea server...Please confirm?

System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture;
    var c = CultureInfo.CreateSpecificCulture("en-US");     

    Console.WriteLine (string.Format(c,"{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));   
ANR
  • 147
  • 1
  • 12
  • 1
    Try to use the Culture in the `Format` method. Like this https://stackoverflow.com/questions/1266093/format-string-by-cultureinfo – Presi Jul 02 '20 at 10:31

1 Answers1

1

I put my comment into an answer. Try to use the Culture in the Format method.

This would look like this:

string.Format(new System.Globalization.CultureInfo("en-GB"), "{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);

This should return 2020-07-02 10:24:33 on your client.

Presi
  • 806
  • 10
  • 26
  • for your particular usecase, better use CultureInfo.InvariantCulture, this is fine for such "pure numeric" outputs. – Ronald Korze Jul 02 '20 at 10:51