国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Unity中獲取時(shí)間戳、日期、時(shí)間、毫秒、秒以相互轉(zhuǎn)換、自定義格式時(shí)間

這篇具有很好參考價(jià)值的文章主要介紹了Unity中獲取時(shí)間戳、日期、時(shí)間、毫秒、秒以相互轉(zhuǎn)換、自定義格式時(shí)間。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

介紹

這里附帶一個(gè)時(shí)間戳和時(shí)間轉(zhuǎn)換的網(wǎng)址

時(shí)間戳是什么

時(shí)間戳就是從1970年1月1日0時(shí)0分0秒起到現(xiàn)在的總毫秒數(shù),為什么時(shí)1970/1/1/00:00:00,因?yàn)榈谝慌_(tái)計(jì)算機(jī)發(fā)明時(shí)間是這個(gè)時(shí)間,所以時(shí)間戳誕生了。

什么時(shí)候用時(shí)間戳

比如說(shuō)你要做一些時(shí)間相關(guān)的功能,那么基本都會(huì)用到時(shí)間戳。而且時(shí)間戳是精確的,比如說(shuō)要做計(jì)時(shí)、寶箱倒計(jì)時(shí)、賬號(hào)禁言、封號(hào)等相關(guān)問(wèn)題你請(qǐng)求服務(wù)器的數(shù)據(jù)一般都是通過(guò)時(shí)間戳來(lái)獲取具體時(shí)間。而且如果與服務(wù)器通訊也可以通過(guò)時(shí)間戳來(lái)做一個(gè)請(qǐng)求響應(yīng)時(shí)間。

獲取時(shí)間

獲取當(dāng)前時(shí)間

//北京時(shí)間
DateTime date1 = DateTime.Now;
Debug.LogError("北京時(shí)間:" + date1);

//國(guó)際時(shí)間
DateTime date2 = DateTime.UtcNow;
Debug.LogError("國(guó)際時(shí)間:" + date2);

unity 獲取時(shí)間戳,Unity,C#高級(jí),unity,c#,時(shí)間,DateTime

獲取時(shí)間戳

//時(shí)間戳方法一
long now1 = DateTime.UtcNow.Ticks;
Debug.LogError("當(dāng)前時(shí)間戳:" + now1);

//時(shí)間戳方法二
long now2 = DateTime.Now.ToUniversalTime().Ticks;
Debug.LogError("當(dāng)前時(shí)間戳:" + now2);

unity 獲取時(shí)間戳,Unity,C#高級(jí),unity,c#,時(shí)間,DateTime

日期轉(zhuǎn)時(shí)間戳

//方法一
TimeSpan st1 = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0);
Debug.LogError("日期轉(zhuǎn)為毫秒時(shí)間戳:" + Convert.ToInt64(st1.TotalMilliseconds));
Debug.LogError("日期轉(zhuǎn)為秒時(shí)間戳:" + Convert.ToInt64(st1.TotalSeconds));
Debug.LogError("日期轉(zhuǎn)為分鐘時(shí)間戳:" + Convert.ToInt64(st1.TotalMinutes));
Debug.LogError("日期轉(zhuǎn)為小時(shí)時(shí)間戳:" + Convert.ToInt64(st1.TotalHours));
Debug.LogError("日期轉(zhuǎn)為天時(shí)間戳:" + Convert.ToInt64(st1.TotalDays));
//方法二
TimeSpan st2 = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0);
Debug.LogError("日期轉(zhuǎn)為毫秒時(shí)間戳:" + Convert.ToInt64(st2.TotalMilliseconds));
Debug.LogError("日期轉(zhuǎn)為秒時(shí)間戳:" + Convert.ToInt64(st2.TotalSeconds));
Debug.LogError("日期轉(zhuǎn)為分鐘時(shí)間戳:" + Convert.ToInt64(st2.TotalMinutes));
Debug.LogError("日期轉(zhuǎn)為小時(shí)時(shí)間戳:" + Convert.ToInt64(st2.TotalHours));
Debug.LogError("日期轉(zhuǎn)為天時(shí)間戳:" + Convert.ToInt64(st2.TotalDays));

//方法三
double tS1 = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000);
Debug.LogError("日期轉(zhuǎn)為時(shí)間戳:" + tS1);

//方法四
double tS2 = ((DateTime.UtcNow.Ticks - 621355968000000000) / 10000);
Debug.LogError("日期轉(zhuǎn)為時(shí)間戳:" + tS2);

unity 獲取時(shí)間戳,Unity,C#高級(jí),unity,c#,時(shí)間,DateTime

時(shí)間戳轉(zhuǎn)日期

        //方法一
        DateTime startTime1 = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc), TimeZoneInfo.Local);
        DateTime dt1 = startTime1.AddMilliseconds(1698766775000);//傳入的時(shí)間戳
        Debug.LogError("時(shí)間戳轉(zhuǎn)時(shí)間:" + dt1);

        //方法二
        DateTime startDateTime = TimeZoneInfo.ConvertTimeFromUtc(new DateTime(1970, 1, 1, 0, 0, 0), TimeZoneInfo.Local);
        long targetTimeStamp = ((long)1698766775000 * 10000);
        TimeSpan targetTS = new TimeSpan(targetTimeStamp);
        DateTime targetDateTime = startDateTime.Add(targetTS);
        Debug.LogError("時(shí)間戳轉(zhuǎn)時(shí)間:" + targetDateTime);

        //方法三
        DateTime startTime3 = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
        DateTime dt3 = startTime3.AddTicks(1698766775000 * 10000);//傳入的時(shí)間戳
        Debug.LogError("時(shí)間戳轉(zhuǎn)時(shí)間:" + dt3);

unity 獲取時(shí)間戳,Unity,C#高級(jí),unity,c#,時(shí)間,DateTime

將時(shí)間戳轉(zhuǎn)換為多久之前

	void Start()
	{
    	Debug.LogError(GetTimeLongAgo(20));
    	Debug.LogError(GetTimeLongAgo(3000));
    	Debug.LogError(GetTimeLongAgo(50000));
    	Debug.LogError(GetTimeLongAgo(864000));
    	Debug.LogError(GetTimeLongAgo(25920000));
    	Debug.LogError(GetTimeLongAgo(61104000));
    
	}
	/// <summary>
    /// 將秒數(shù)時(shí)間戳轉(zhuǎn)換為多久之前。傳入時(shí)間戳t(t= 當(dāng)前時(shí)間戳() - 指定時(shí)間的時(shí)間戳 )
    /// </summary>
    /// <param name="t"></param>
    /// <returns></returns>
    public string GetTimeLongAgo(double t)
    {
        string str = "";
        double num;
        if (t < 60)
        {
            str = string.Format("{0}秒前", t);
        }
        else if (t >= 60 && t < 3600)
        {
            num = Math.Floor(t / 60);
            str = string.Format("{0}分鐘前", num);
        }
        else if (t >= 3600 && t < 86400)
        {
            num = Math.Floor(t / 3600);
            str = string.Format("{0}小時(shí)前", num);
        }
        else if (t > 86400 && t < 2592000)
        {
            num = Math.Floor(t / 86400);
            str = string.Format("{0}天前", num);
        }
        else if (t > 2592000 && t < 31104000)
        {
            num = Math.Floor(t / 2592000);
            str = string.Format("{0}月前", num);
        }
        else
        {
            num = Math.Floor(t / 31104000);
            str = string.Format("{0}年前", num);
        }
        return str;
    }

unity 獲取時(shí)間戳,Unity,C#高級(jí),unity,c#,時(shí)間,DateTime

星期

        //方案一
        string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
        string week = Day[Convert.ToInt32(DateTime.Now.DayOfWeek.ToString("d"))].ToString();
        Debug.LogError(week);

        //方案二
        Debug.LogError(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek));

        //方案三
        Debug.LogError(DateTime.Today.DayOfWeek.ToString());

unity 獲取時(shí)間戳,Unity,C#高級(jí),unity,c#,時(shí)間,DateTime

自定義格式時(shí)間

DateTime dateTime = DateTime.Now;
string strNowTime = string.Format("{0:D}-{1:D}-{2:D}-{3:D}-{4:D}-{5:D}-{6:D}", dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond);

Debug.LogError(strNowTime);

unity 獲取時(shí)間戳,Unity,C#高級(jí),unity,c#,時(shí)間,DateTime

總結(jié)

這里其實(shí)還有很多中方式,上面知識(shí)其中的一些,基本是夠用了,歡迎評(píng)論區(qū)補(bǔ)充文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-751895.html

到了這里,關(guān)于Unity中獲取時(shí)間戳、日期、時(shí)間、毫秒、秒以相互轉(zhuǎn)換、自定義格式時(shí)間的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • MySQL時(shí)間戳與日期格式的相互轉(zhuǎn)換

    在MySQL數(shù)據(jù)庫(kù)中,時(shí)間戳(timestamp)和日期格式(date format)是常用的數(shù)據(jù)類型。時(shí)間戳表示從1970年1月1日零時(shí)到特定日期時(shí)間的秒數(shù),而日期格式則以年-月-日的形式表示日期。在MySQL中,我們可以使用函數(shù)來(lái)相互轉(zhuǎn)換時(shí)間戳和日期格式。下面我將詳細(xì)介紹如何進(jìn)行這些轉(zhuǎn)換

    2024年02月03日
    瀏覽(25)
  • Linux :: 時(shí)間日歷指令【2】:date 指令 與 時(shí)間戳(及日期與時(shí)間戳的相互轉(zhuǎn)換)

    前言:本篇是 Linux 基本操作篇章的內(nèi)容! 筆者使用的環(huán)境是基于騰訊云服務(wù)器:CentOS 7.6 64bit。 學(xué)習(xí)集: C++ 入門到入土?。?!學(xué)習(xí)合集 Linux 從命令到網(wǎng)絡(luò)再到內(nèi)核!學(xué)習(xí)合集 目錄索引: 1. 時(shí)間戳的認(rèn)識(shí) 2. Linux 下獲取時(shí)間戳方式:date +%s 3. 時(shí)間 = 時(shí)間戳 4. 時(shí)間戳 = 時(shí)間:

    2024年02月15日
    瀏覽(23)
  • 前端中不同格式的日期相互轉(zhuǎn)換(字符串、時(shí)間戳)js相關(guān)

    前端中不同格式的日期相互轉(zhuǎn)換(字符串、時(shí)間戳)js相關(guān)

    在項(xiàng)目中遇到了,需要實(shí)現(xiàn)字符串和Unix時(shí)間戳的相互轉(zhuǎn)換,隨手記錄一下。 我使用的組件庫(kù)為Naive UI,涉及到的組件為日期選擇器(Date Picker)。作者在文檔中寫(xiě)道: 實(shí)話說(shuō)我不喜歡這個(gè) feature,因?yàn)槎鄶?shù)情況下,傳遞時(shí)間字符串不是個(gè)最佳實(shí)踐。但是現(xiàn)實(shí)世界是復(fù)雜的,我

    2024年02月02日
    瀏覽(25)
  • python獲取當(dāng)前時(shí)間(年-月-日 時(shí):分:秒:毫秒),提取當(dāng)前日期/時(shí)間數(shù)字,獲取程序運(yùn)行的時(shí)間差(時(shí):分:秒),讓程序停止xx秒【兩種方法,第二種方法精度較高】

    python獲取當(dāng)前時(shí)間(年-月-日 時(shí):分:秒:毫秒),提取當(dāng)前日期/時(shí)間數(shù)字,獲取程序運(yùn)行的時(shí)間差(時(shí):分:秒),讓程序停止xx秒【兩種方法,第二種方法精度較高】

    目錄 》》》第一種方法,代碼如下:(獲取當(dāng)前時(shí)間,提取當(dāng)前日期/時(shí)間數(shù)字) 》》》第二種方法,代碼如下:(獲取當(dāng)前時(shí)間,提取日期/時(shí)間數(shù)字,獲取時(shí)間差【時(shí):分:秒】) 》》》第一種方法,代碼如下:(獲取當(dāng)前時(shí)間,提取當(dāng)前日期/時(shí)間數(shù)字) 第一種方法的運(yùn)行

    2024年02月16日
    瀏覽(26)
  • JS日期與字符串相互轉(zhuǎn)換(時(shí)間格式化YYYY-MM-DD,Dayjs的使用)

    JS日期與字符串相互轉(zhuǎn)換(時(shí)間格式化YYYY-MM-DD,Dayjs的使用)

    文章內(nèi)容 文章鏈接 JS數(shù)組對(duì)象—— 根據(jù)日期進(jìn)行排序 , 按照時(shí)間進(jìn)行升序或降序排序 https://blog.csdn.net/XSL_HR/article/details/128579840?spm=1001.2014.3001.5501 JS日期時(shí)間格式化—— 數(shù)字日期轉(zhuǎn)中文日期 (封裝函數(shù),dayjs轉(zhuǎn)換時(shí)間格式) https://blog.csdn.net/XSL_HR/article/details/128607024?spm=100

    2024年01月18日
    瀏覽(22)
  • logstash毫秒時(shí)間戳轉(zhuǎn)日期以及使用業(yè)務(wù)日志時(shí)間戳替換原始@timestamp

    logstash毫秒時(shí)間戳轉(zhuǎn)日期以及使用業(yè)務(wù)日志時(shí)間戳替換原始@timestamp

    在使用Kibana觀察日志排查問(wèn)題時(shí)發(fā)現(xiàn)存在很多組的@timestamp 數(shù)據(jù)一樣,如下所示 詳細(xì)觀察內(nèi)部數(shù)據(jù)發(fā)現(xiàn)其中日志數(shù)據(jù)有一個(gè)timestamp字段保存的是業(yè)務(wù)日志的毫秒級(jí)時(shí)間戳,經(jīng)過(guò)和@timestamp數(shù)據(jù)對(duì)比發(fā)現(xiàn)二者的時(shí)間不匹配。經(jīng)過(guò)分析得知@timestamp是按照l(shuí)ogstash插入es數(shù)據(jù)的時(shí)間來(lái)排

    2023年04月11日
    瀏覽(38)
  • java實(shí)現(xiàn)時(shí)間格式轉(zhuǎn)換(int整數(shù)類型的秒/毫秒---時(shí)分秒毫秒)

    秒或毫秒類型的數(shù)值轉(zhuǎn)為指定格式的時(shí)間格式: 運(yùn)行結(jié)果如下: 當(dāng)然,還可以指定自定義的格式轉(zhuǎn)化顯示。

    2024年02月11日
    瀏覽(29)
  • python time 獲取毫秒級(jí)時(shí)間戳

    1、time 獲取秒級(jí)時(shí)間戳,格式化顯示 結(jié)果: 2、datetime 獲取當(dāng)前日期時(shí)間 結(jié)果: 3、日期時(shí)間之間的轉(zhuǎn)換 3.1、字符串轉(zhuǎn) time 3.2、字符串轉(zhuǎn) time 3.3、示例

    2024年02月16日
    瀏覽(19)
  • PHP實(shí)現(xiàn)獲取毫秒時(shí)間戳的方法

    PHP獲取毫秒時(shí)間戳,利用microtime()函數(shù) php本身沒(méi)有提供返回毫秒數(shù)的函數(shù),但提供了一個(gè)microtime()函數(shù),借助此函數(shù),可以很容易定義一個(gè)返回毫秒數(shù)的函數(shù)。 php的毫秒是沒(méi)有默認(rèn)函數(shù)的,但提供了一個(gè)microtime()函數(shù),該函數(shù)返回包含兩個(gè)元素,一個(gè)是秒數(shù),一個(gè)是小數(shù)表示

    2024年02月15日
    瀏覽(27)
  • c++ 獲取當(dāng)前時(shí)間(精確至秒、毫秒和微妙)

    概念 時(shí)間單位 小時(shí)(hours): std::chrono::hours 分鐘(minutes): std::chrono::minutes 秒(seconds): std::chrono::seconds 毫秒(milliseconds): std::chrono::milliseconds 微秒(microseconds): std::chrono::microseconds 納秒(nanoseconds): std::chrono::nanoseconds 時(shí)間精度 整數(shù)類型精度: std::chrono::duratio

    2024年02月04日
    瀏覽(20)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包