【发布时间】:2015-06-30 23:27:48
【问题描述】:
如何将时间转换为公共 int,我需要将 TimeSpan 差异转换为秒,然后将其保存为公共 int。
在 4 小时 22 分 34 秒内进入 15754。
using UnityEngine;
using System.Collections;
using System;
public class Timeload : MonoBehaviour {
DateTime currentDate;
DateTime oldDate;
void Start()
{
//Store the current time when it starts
currentDate = System.DateTime.Now;
//Grab the old time from the player prefs as a long
long temp = Convert.ToInt64(PlayerPrefs.GetString("sysString"));
//Convert the old time from binary to a DataTime variable
DateTime oldDate = DateTime.FromBinary(temp);
print("oldDate: " + oldDate);
//Use the Subtract method and store the result as a timespan variable
TimeSpan difference = currentDate.Subtract(oldDate);
print("Difference: " + difference);
}
void OnApplicationQuit()
{
//Savee the current system time as a string in the player prefs class
PlayerPrefs.SetString("sysString", System.DateTime.Now.ToBinary().ToString());
print("Saving this date to prefs: " + System.DateTime.Now);
}
}
【问题讨论】:
-
只保存为日期时间有什么问题?
-
我有点想用它来与其他整数相乘
-
你是对的...thanx
标签: c# datetime time unity3d int