Unity3D获取系统当前时间,并格式化显示
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获取系统当前时间,并格式化显示的更多相关文章
- java 获取系统当前时间并格式化
java 获取系统当前时间并格式化 CreateTime--2018年5月9日11:41:00 Author:Marydon 实现方式有三种 updateTime--2018年7月23日09点32 ...
- 使用date类和format类对系统当前时间进行格式化显示
一:Date------------String 代码1:(代码二对显示出来的时间格式进行优化) package DateDemo; import java.text.SimpleDateFormat ...
- Java基础 - Date的相关使用(获取系统当前时间)
前言: 在日常Java开发中,常常会使用到Date的相关操作,如:获取当前系统时间.获取当前时间戳.时间戳按指定格式转换成时间等.以前用到的时候,大部分是去网上找,但事后又很快忘记.现为方便自己今后查 ...
- Oracle,MySQL,sqlserver三大数据库如何获取系统当前时间
Oracle中如何获取系统当前时间:用SYSDATE() MySQL中获取系统当前时间主要有以下几点: (1)now()函数以('YYYY-MM-dd HH:mm:SS')返回当前的日期时间,可以直接 ...
- android service 样例(电话录音和获取系统当前时间)
关于android service 的具体解释请參考: android四大组件--android service具体解释.以下将用两个实例具体呈现Android Service的两种实现. 一个是st ...
- java获取系统指定时间年月日
java获取系统指定时间年月日 private String setDateTime(String falg) { Calendar c = Calendar.getInstance(); c.set ...
- 使用js时,如何获取系统当前时间并且得到格式为"yyyy年MM月"的日期
1.使用js时,如何获取系统当前时间并且得到格式为"yyyy年MM月"的日期: 1 var newdate = new Date(); 2 var nowyear = newdat ...
- C++ 获取系统当前时间(日历时)
获取系统当前时间(日历时) //Linux & C++11 #include <chrono> #include <ctime> using namespace std ...
- C# 获取系统开机时间
原文:C# 获取系统开机时间 /// /// 获取系统开机时间 /// /// private DateTime GetComput ...
随机推荐
- C++多态等知识点
分清虚函数和纯虚函数的区别:(1).虚函数是函数前加关键字virtual,一般定义格式为:virtual 类型 函数名 (参数表){ 函数体 } (2).纯虚函数的生命格式为: virtual 类型 ...
- idea遇到的坑
(1)在main方法中启动报错: 或 经检查是pom.xml文件依赖的问题,解决方法1.将如下截图的<scope>去掉就好了 解决方法2:scope不删掉,在下面这里执行run: (2)如 ...
- HTML调用PC摄像头【申明:来源于网络】
HTML调用PC摄像头[申明:来源于网络] ---- 地址:http://www.oschina.net/code/snippet_2440934_55195 <!DOCTYPE html> ...
- 微信小程序(微信应用号)组件讲解[申明:来源于网络]
微信小程序(微信应用号)组件讲解[申明:来源于网络] 地址:http://www.cnblogs.com/muyixiaoguang/p/5902008.html
- 1.7Oob方法的作用
public class Exse2 { public static void main(String[] args) { sumIntLong(10,15); sumIntLong(20,30); ...
- Weex小笔记(自己理解,有错请指正)
在Eros中,做的内容是封装了一些常用的框架,并且优化开发流程为将前端Vue文件打包出资源文件导入项目工程中(本地加载模式,需要注册文件.验证文件),然后原生移动端通过OC写module(功能模块类) ...
- 最全的MonkeyRunner自动化测试从入门到精通(6)
eclipse中进行插入PyDev插件的使用步骤一:monkeyrunner环境变量的配置.在Android Sdk中的tools目录下,拷贝路径,进行配置环境变量.与上面的配置方法一样,在这里不做过 ...
- linux+nginx+phpfpm 访问出现Access denied错误解决方案
linux上安装nginx,php-fpm后访问页面一直出现Access denied错误. 网上搜原因大概如下图: 我试了第一个方案,然后就好了.
- Centos7.1环境下搭建SVN
环境准备: 系统 配置 IP Centos7.1 1核2G+60GB硬盘 10.10.28.204 1.安装 sudo yum install subversion 查看版本 svnserve –-v ...
- iot-web增加apis-namespace组件
1 文件夹复制 apis 2 增加 3 增加module