unity 根据纪元时间(1970/1/1)转换为DateTime
发布日期:2021-06-30 19:37:45
浏览次数:3
分类:技术文章
本文共 970 字,大约阅读时间需要 3 分钟。
首先,先说一下怎么根据DateTime获得时间的长整型
public static uint GetLongTime(){ DateTime time197011 = new DateTime(1970, 1, 1); DateTime time = DateTime.Now; TimeSpan ts = time - time197011; TimeZone localZone = TimeZone.CurrentTimeZone; TimeSpan off = localZone.GetUtcOffset(time); ts -= off; return (uint)ts.TotalSeconds;}
然后,下面就是根据长整型转DateTime
public DateTime SystemTime2DateTime(){ DateTime dt197011 = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long lsystemTime = long.Parse(GetLongTime() + "0000000"); TimeSpan toNowTs = new TimeSpan(lsystemTime); return dt197011.Add(toNowTs);}
根据DateTime输出具体的年月日可以这样做
DateTime dt=SystemTime2DateTime();Debug.Log(dt.ToString("yyyy/MM/dd HH:mm:ss")); //24小时制//Debug.Log(dt.ToString("yyyy/MM/dd hh:mm:ss")); //12小时制//
如果要获取当前时间的时分秒,则直接可以这样:
Debug.Log(DataTime.Now.ToString("HH:mm:ss")); //24小时制Debug.Log(DataTime.Now.ToString("hh:mm:ss")); //12小时制
转载地址:https://linxinfa.blog.csdn.net/article/details/46366111 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
做的很好,不错不错
[***.243.131.199]2024年04月24日 04时29分50秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
linux内存的寻址方式
2019-04-30
ubunut16.04的pip3出现问题,重新安装pip3
2019-04-30
how2heap-double free
2019-04-30
how2heap-fastbin_dup_consolidate
2019-04-30
orw_shellcode_模板
2019-04-30
[fmt+shellcode]string
2019-04-30
fmt在bss段(neepusec_easy_format)
2019-04-30
[double free] 9447 CTF : Search Engine
2019-04-30
python 函数式编程
2019-04-30
python编码
2019-04-30
scala maven plugin
2019-04-30
flink 1-个人理解
2019-04-30
redis cli
2019-04-30
redis api
2019-04-30
flink physical partition
2019-04-30
java 解析json
2019-04-30
java http请求
2019-04-30
tensorflow 数据格式
2019-04-30
tf rnn layer
2019-04-30