using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Time_Size : MonoBehaviour
{
public string msg;
private void Start()
{
DateTime date = DateTime.Now.ToLocalTime(); //当前系统时间
string data1 = "2021/1/1 12:12:12"; // "/" 跟 "-" 效果是一样的
//string data3 = "2021-01-01 12:12:12";
CompanyDate(date .ToString (), data1, ref msg);
}
public void CompanyDate(string dateStr1, string dateStr2, ref string msg)
{
//将日期字符串转换为日期对象
DateTime t1 = Convert.ToDateTime(dateStr1);
DateTime t2 = Convert.ToDateTime(dateStr2);
//通过DateTIme.Compare()进行比较()
int num = DateTime.Compare(t1, t2);
//t1> t2
if (num > 0)
{
msg = "t1:(" + dateStr1 + ")大于" + "t2(" + dateStr2 + ")";
}
//t1= t2
if (num == 0)
{
msg = "t1:(" + dateStr1 + ")等于" + "t2(" + dateStr2 + ")";
}
//t1< t2
if (num < 0)
{
msg = "t1:(" + dateStr1 + ")小于" + "t2(" + dateStr2 + ")";
}
}
// Update is called once per frame
void Update()
{
}
}
Unity 比较时间大小
最新推荐文章于 2024-08-16 18:57:09 发布