Unity中展示当前时间

先看效果

代码如下

cs 复制代码
   private IEnumerator ShowTimer()
   {
       while (true)
       {
           yield return new WaitForSeconds(1f);
           DateTime currentDateTime = DateTime.Now;

           // 获取星期几的中文名称
           string dayOfWeek = currentDateTime.ToString("dddd", new CultureInfo("zh-CN"));

           // 格式化时间
           string formattedDate = currentDateTime.ToString("yyyy年M月d日 ") + dayOfWeek + " " +
                                  currentDateTime.ToString("HH:mm:ss");
           timer.text = formattedDate;
       }
   }
// StartCoroutine(ShowTimer());开启该协程
相关推荐
点心的游戏开发世界4 小时前
GDScript 入门笔记(十一):Lambda 与匿名函数
开发语言·笔记·游戏引擎·godot
phltxy4 小时前
C语言操作符详解
java·c语言·算法
步行cgn5 小时前
@Configuration 详解:Spring 配置类的核心注解
java·后端·spring
sunshine22 girl5 小时前
Java学习一 环境配置2 安装和基本使用Idea
java·学习·intellij-idea
嘿嘿-667 小时前
Windows 一键使用 GPT-6 Astra:Codex CLI 配置教程
java·人工智能·windows·gpt·chatgpt·web
策案案案8 小时前
YOLO: 将AI Agents嵌入到IntelliJ IDEA
java·大数据·人工智能·笔记·yolo·microsoft·intellij-idea
辰烨chenye9 小时前
LeetCode Hot 100 题解 · 堆篇
java·算法·leetcode
shehuiyuelaiyuehao10 小时前
算法29,前缀和,除自身以外的数组的乘积
java·数据结构·算法
小刘在重生~10 小时前
Java常用类|String类详解 + BigDecimal精准计算(含面试题)
java·开发语言·python
随遇而安zx10 小时前
【多线程】---JMM 与 volatile 深度解析
java·多线程