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 ...
随机推荐
- hibernate06--参数的绑定
创建Dept实体类 以及 对应的 Dept.hbm.xml文件 /** * @author 小豆腐 * *部门的实体类 */ public class Dept { private Integer d ...
- CSS div 高度满屏
方法一: 通过JQuery,获取窗体的高度,设置给对应的div.代码如下 ht = $(document.body).height(); $(); 缺点:由于浏览器是先解析css,后执行JS,导致页面 ...
- C语言函数strstr
函数原型: extern char *strstr(char *str1, const char *str2); 语法: * strstr(str1,str2) 参数: str1: 被查找目标 ...
- Oracle课程档案,第六天
体系结构: instance:实例 database:数据库 RAC:多实例对一个数据库 SGA:最大总数 (系统全局区域)缓存区 PGA:其中的一块, 也是一个缓存区 server process: ...
- python全栈开发 * 07知识点汇总 * 180607
07 set集合,深浅拷⻉以及部分知识点补充 一.while,for 循环知识点补充 二.int, str的相关操作 1.列表变字符串 # lst=["红","橙&qu ...
- Appium下载安装及环境配置
下载地址:https://bitbucket.org/appium/appium.app/downloads/ windows安装: 下载 AppiumForWindows.zip 解压 Appium ...
- Spring Boot核心注解@SpringBootApplication
一.作用 @SpringBootApplication是一个组合注解,用于快捷配置启动类. 二.用法 可配置多个启动类,但启动时需选择以哪个类作为启动类来启动项目. 三.拆解 1.拆解 ...
- oracle_18c新建用户用normal登陆失败
工具介绍:win10系统,使用的是oracle18c. 首先说一下oracle18c的特性,在oracle18c创建用户要以c##开头,比如: --创建新用户create user c##test_u ...
- 【JVM】-NO.115.JVM.1 -【JDK11 HashMap详解-4-伸展树、B树】
.Style:Mac Series:Java Since:2018-09-10 End:2018-09-10 Total Hours:1 Degree Of Diffculty:5 Degree Of ...
- json to entity in api
using (var client = new HttpClient()) { var WVMId = DB.Vehicles.Where(v => v.Id == new Guid(vehic ...