制作一个钟表,要求效果如下图:

由于每一部分的字体大小不同,我分别使用了不同的Text控件。(不懂dalao们有没有更科学的办法)

把这些Text控件包含在一个Object下,给该Object定义一个脚本,分别引用这些控件。

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; /// <summary>
/// 显示当前的系统时间
/// </summary>
public class TimeScript : MonoBehaviour { public Text HourText; // 时
public Text MinuteText; // 分
public Text DateText; // 23
public Text MonthText; // MAR
public Text WeekText; // THU // Use this for initialization
void Start () { } // Update is called once per frame
void Update () {
//取得现在的时间
DateTime now = DateTime.Now; HourText.text = now.ToString("HH"); // HH是24时制,hh是12时制
MinuteText.text = now.ToString("mm");
DateText.text = now.ToString("dd");
MonthText.text = now.ToString("MMMM", new System.Globalization.CultureInfo("en-us")).Substring(0, 3); // 月份只要洋文的前三个字母
WeekText.text = now.ToString("dddd").Substring(0, 3); // 星期只要洋文的前三个字母 }
}

小结:

  • 时间字符串使用DateTime类。
  • 格式化的格式参见 http://www.cnblogs.com/polk6/p/5465088.html
  • 月份获取到的是数字(如12月是返回12),想要改成英文,国际化的方法参见上面代码(省去自己写12个枚举)。

其他字符串操作的相关参考:

http://www.manew.com/blog-1121-845.html

【Unity/C#】DateTime时间字符串,月份用英文显示的更多相关文章

  1. [Selenium] 数字显示的月份转换为英文显示

    如果只需要英文的前三位字母,可以自己截取.

  2. python中时间戳,datetime 和时间字符串之间得转换

    # datetime时间转为字符串def Changestr(datetime1):    str1 = datetime1.strftime('%Y-%m-%d %H:%M:%S')    retu ...

  3. Python的time(时间戳与时间字符串互相转化)

    strptime("string format")字符串如"20130512000000"格式的 输入处理函数 localtime(float a)时间戳的输入 ...

  4. python datetime 时间日期处理小结

    python datetime 时间日期处理小结 转载请注明出处:http://hi.baidu.com/leejun_2005/blog/item/47f340f1a85b5cb3a50f5232. ...

  5. 格式化日期时间字符串 Get-Date -Uformat , -format

    #将字符串格式化为时间格式 $dateTimeStr = '20141231T23:59:59' $format = 'yyyyMMddTHH:mm:ss' $formatProvider = [Gl ...

  6. 第三十二节,datetime时间模块

    首先要引入import datetime时间模块 datetime.date.today()模块函数 功能:输出系统年月日输出格式 2016-01-26[无参] 使用方法:datetime.date. ...

  7. python 时间字符串和时间戳之间的转换

    https://blog.csdn.net/qq_37193537/article/details/78987949   1.将字符串的时间转换为时间戳    方法:        a = " ...

  8. day5模块学习 -- time、datetime时间模块

    1.定义 模块:用来从逻辑上组织python(变量,函数,类,逻辑:实现一个功能)代码,本质就是.py结尾的python文件(文件名:test.py,对应的模块名test) 包:用来从逻辑上组织模块的 ...

  9. python--模块之time,datetime时间模块

    time: 表示时间的三种方式:时间戳.格式化的时间字符串.元组时间戳是计算机能够识别的时间:时间字符串是我们能够看懂的时间:元组是用来操作时间: 导入时间模块import time 1,时间戳(ti ...

随机推荐

  1. Android API之android.provider.ContactsContract

    android.provider.ContactsContract ContactsContract是联系人provider和app的contract.定义了已支持的URL和column.取代了之前的 ...

  2. python中如何对list之间求交集,并集和差集

    最近遇到一个从list a里面去除list b的元素的问题,由于a很大,b也不小.所以遇到点困难,现在mark一下. 先说最简单的方法: a = [1, 2, 3, 4, 5, 6, 7, 8, 9, ...

  3. 开发完 iOS 应用,接下去你该做的事

    iOS专项总结 一个应用经过多次迭代后告一段落,接下去我们在技术上还可以做些什么呢?答案是提高代码的整体质量.关于这方面,除了我们常喊的 重构,测试也非常重要. 博主近期给我们的 iOS客户端代码来了 ...

  4. 【LeetCode】150. Evaluate Reverse Polish Notation

    Evaluate Reverse Polish Notation Evaluate the value of an arithmetic expression in Reverse Polish No ...

  5. linux常见面试题及答案

    1. 在Linux系统中,以文件方式访问设备. 2. Linux内核引导时,从文件/etc/fstab中读取要加载的文件系统. 3. Linux文件系统中每个文件用i字节来标识. 4. 全部磁盘块由四 ...

  6. ubuntu 安装ssh 服务

    百度地址: http://jingyan.baidu.com/article/00a07f38a5c05482d128dc5f.html

  7. 使用SecureCRT连接linux

    1.登录之后进入linux系统,输入ifconfig(interfaces config)查看网卡信息 2.设置VMWare的虚拟机连接方式为仅主机模式 3.查看VMWare为仅主机模式虚拟网卡IP地 ...

  8. Apache Storm使用

    Apache Storm 是 Apache 基金会的开源的分布式实时计算系统.与 Hadoop 的批处理相类似,Storm 可以对大量的数据流进行可靠的实时处理,这一过程也称为“流式处理”,是分布式大 ...

  9. 程序猿修仙之路--数据结构之你是否真的懂数组? c#socket TCP同步网络通信 用lambda表达式树替代反射 ASP.NET MVC如何做一个简单的非法登录拦截

    程序猿修仙之路--数据结构之你是否真的懂数组?   数据结构 但凡IT江湖侠士,算法与数据结构为必修之课.早有前辈已经明确指出:程序=算法+数据结构  .要想在之后的江湖历练中通关,数据结构必不可少. ...

  10. 转:使用Mosquitto-Auth-Plugin对mqtt客户端进行验证

    https://www.lixiaodong.com/?p=1631.安装需要的包sudo apt-get install libc-ares-dev libcurl4-openssl-dev lib ...