Unity 获取系统当前时间,并格式化显示。通过“System.DateTime”获取系统当前的时间,然后通过格式化把获得的时间格式化显示出来,具体如下:

1、打开Unity,新建一个空工程,Unity界面如下图

2、在工程中新建一个脚本,可以命名为“CurrrentTimeTest”,选中“CurrrentTimeTest”,双击打开脚本。

3、在打开 的脚本上进行编辑,首先设置几个变量存取当前时间的时分秒,年月日,然后把取得到的时间进行格式化输出,具体如下图

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; public class CurrrentTimeTest : MonoBehaviour { private Text CurrrentTimeText;
private int hour;
private int minute;
private int second;
private int year;
private int month;
private int day; // Use this for initialization
void Start () {
CurrrentTimeText = GetComponent<Text>(); } // Update is called once per frame
void Update () {
//获取当前时间
hour = DateTime.Now.Hour;
minute = DateTime.Now.Minute;
second = DateTime.Now.Second;
year = DateTime.Now.Year;
month = DateTime.Now.Month;
day = DateTime.Now.Day; //格式化显示当前时间
CurrrentTimeText.text = string.Format("{0:D2}:{1:D2}:{2:D2} " + "{3:D4}/{4:D2}/{5:D2}", hour, minute, second, year, month, day); #if UNITY_EDITOR
Debug.Log("W now " + System.DateTime.Now); //当前时间(年月日时分秒)
Debug.Log("W utc " + System.DateTime.UtcNow); //当前时间(年月日时分秒)
#endif
}
}

4、脚本编译正确后,回到Unity界面,在场景中新建一个“Text”,适当调整好位置与大小,然后把“CurrentTimeTest”赋给“Text”,具体如下图

5、运行场景,即可以看到当前时间的显示,具体如下图

Unity3D获取系统当前时间,并格式化显示的更多相关文章

  1. java 获取系统当前时间并格式化

      java 获取系统当前时间并格式化 CreateTime--2018年5月9日11:41:00 Author:Marydon 实现方式有三种 updateTime--2018年7月23日09点32 ...

  2. 使用date类和format类对系统当前时间进行格式化显示

    一:Date------------String 代码1:(代码二对显示出来的时间格式进行优化) package DateDemo; import java.text.SimpleDateFormat ...

  3. Java基础 - Date的相关使用(获取系统当前时间)

    前言: 在日常Java开发中,常常会使用到Date的相关操作,如:获取当前系统时间.获取当前时间戳.时间戳按指定格式转换成时间等.以前用到的时候,大部分是去网上找,但事后又很快忘记.现为方便自己今后查 ...

  4. Oracle,MySQL,sqlserver三大数据库如何获取系统当前时间

    Oracle中如何获取系统当前时间:用SYSDATE() MySQL中获取系统当前时间主要有以下几点: (1)now()函数以('YYYY-MM-dd HH:mm:SS')返回当前的日期时间,可以直接 ...

  5. android service 样例(电话录音和获取系统当前时间)

    关于android service 的具体解释请參考: android四大组件--android service具体解释.以下将用两个实例具体呈现Android Service的两种实现. 一个是st ...

  6. java获取系统指定时间年月日

    java获取系统指定时间年月日 private String setDateTime(String falg) { Calendar c = Calendar.getInstance(); c.set ...

  7. 使用js时,如何获取系统当前时间并且得到格式为"yyyy年MM月"的日期

    1.使用js时,如何获取系统当前时间并且得到格式为"yyyy年MM月"的日期: 1 var newdate = new Date(); 2 var nowyear = newdat ...

  8. C++ 获取系统当前时间(日历时)

    获取系统当前时间(日历时) //Linux & C++11 #include <chrono> #include <ctime> using namespace std ...

  9. C# 获取系统开机时间

    原文:C# 获取系统开机时间 ///         ///  获取系统开机时间          ///         ///         private DateTime GetComput ...

随机推荐

  1. 23.react-router 路由

    箭头函数扩展: 箭头函数: functoin 函数名(参数){    函数体 } 箭头函数: 1.把function删掉 , 2.参数和{}之间加上 箭头=> 简写: 1.参数的简写:只有一个参 ...

  2. swust oj 1069

    图的按录入顺序广度优先搜索 5000(ms) 10000(kb) 2347 / 4868 Tags: 广度优先 图的广度优先搜索类似于树的按层次遍历,即从某个结点开始,先访问该结 点,然后访问该结点的 ...

  3. vue的属性样式绑定,

    <template> <div id="app"> <div v-html="H"></div>  //绑定ht ...

  4. php钩子原理和实现

    2017年3月18日17:22:52 php版本 5.6.27 5.3以下和5.3以上的版本在PHP类与对象区别很大,请注意 其实原理很简单,有些人把事情弄的过于发杂,其实就是调用某个目录下的比如/h ...

  5. Luogu 1042 - 乒乓球 - [简单模拟]

    题目链接:https://www.luogu.org/problemnew/show/P1042 题目背景国际乒联现在主席沙拉拉自从上任以来就立志于推行一系列改革,以推动乒乓球运动在全球的普及.其中 ...

  6. ssm中整合Mybatis可以扫描到放在mapper下面的xml文件的方法

    mybatis配置时出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 解决方法有两种: ...

  7. 对stm32寄存器的理解(个人理解,大神轻喷)

    学习了stm32有一年了,今天想来写写自己对寄存器的理解,帮助那些有志学习stm32的朋友们少走一些弯路. ---------------------------------------------- ...

  8. python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告(二)

    可以参考 python+requests接口自动化完整项目设计源码(一)https://www.cnblogs.com/111testing/p/9612671.html 原文地址https://ww ...

  9. cocos2d-x JS 富文本

    var str1 = "兑换成功后,系统会生成“";var str2 = "红包兑换码";var str3 = "”,请复制该兑换码,并粘贴在&quo ...

  10. 当业务逻辑没错,直接mapper里面出错时

    仔细检查,发现sql语句写的也没问题,但就是出错 slide_show_img_url = #{slideShowImgUrl,jdbcType=VARCHAR}, where goods_slide ...