我正在尝试使用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)