Home>
What you do n’t understand

DateTime.Now.ToString () is used to record the date on the Nifkura mobile backend, but on Unity, for some years like "2019/11/21 13:52:40" It comes first, but when run on Android, the moon comes first like "11/21/2019 13:54:13".

Source code
float resultTime = Time.time-playTime;
        playRecord ["userId"] = PlayerPrefs.GetString ("UserID");
        playRecord ["finishTime"] = DateTime.Now.ToString ();// The problem part is here
        playRecord ["playTime"] = resultTime;
        playRecord ["correct"] = correct;
        playRecord ["incorrect"] = incorrect;
        playRecord.SaveAsync ();

Is there no choice but to format it using DateTime.Now.Day etc. to unify it from each device?
I would like to know if there is a way to unify something.

  • Answer # 1

    Hello.
    TheToStringmethod is affected by the locale (regional information) by default, so specify the locale explicitly or specify the format.

    // Specify locale
    DateTime.Now.ToString (new CultureInfo ("ja-JP"));// 2019/11/21 14:33:06
    DateTime.Now.ToString (new CultureInfo ("en-US"));// 11/21/2019 14:33:06
    // format specification
    DateTime.Now.ToString ("yyyyMMdd-HHmmss") // 20191121-143306

  • Answer # 2

    Here is a detailed document on date and time formatting.

    DateTime.ToString method
    https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tostring

    Standard date and time format string
    https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings

    Custom date and time format string
    https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings