小编Waf*_*fer的帖子

为什么Convert.ToDateTime()在这个例子中不起作用?

我正在尝试使用System.DateTime.Now.ToString()和Convert.ToDateTime,并遇到了一些奇怪的行为.我已将问题缩小到Convert.ToDateTime.由于某种原因,使用System.DateTime.Now设置的DateTime类型与从字符串转换的DateTime类型不同.但是,当您输出其中任何一个时,它们看起来是相同的.

(我尝试使用Trim(),TrimStart()和TrimEnd()无济于事.)

在统一运行之后,这是控制台中的输出:http: //imgur.com/1ZIdPH4

using UnityEngine;
using System;

public class DateTimeTest : MonoBehaviour {
    void Start () {
        //Save current time as a DateTime type
        DateTime saveTime = System.DateTime.Now;
        //Save above DateTime as a string
        string store = saveTime.ToString();
        //Convert it back to a DateTime type
        DateTime convertedTime = Convert.ToDateTime(store);

        //Output both DateTimes
        Debug.Log(saveTime + "\n" + convertedTime);

        //Output whether or not they match.
        if (saveTime == convertedTime)
            Debug.Log("Match: Yes");
        else
            Debug.Log("Match: No");

        //Output both DateTimes converted to …
Run Code Online (Sandbox Code Playgroud)

c# datetime unity-game-engine

4
推荐指数
1
解决办法
889
查看次数

标签 统计

c# ×1

datetime ×1

unity-game-engine ×1