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());开启该协程
相关推荐
键盘歌唱家21 小时前
Spring AI 入门分享:它和“直接调 API“到底差在哪
java·人工智能·spring
宸丶一21 小时前
Day 10:LangGraph - Agent 的图执行引擎
java·windows·python
hikktn21 小时前
Excel 导出 OOM 预防实战:30 万行从堆溢出到 50MB 的演进
java·excel·easyexcel
风味蘑菇干21 小时前
WTomcat服务器
java·服务器
魔士于安21 小时前
unity 音乐会场景 unity2022
游戏·unity·游戏引擎·贴图·模型
燕-孑21 小时前
tomcat详解(基础到高级生产)
java·tomcat
码不停蹄的玄黓1 天前
Spring Bean 生命周期
java·后端·spring
西安邮电大学1 天前
分治算法详细讲解
java·后端·其他·算法·面试
摇滚侠1 天前
Mybatis 入门到项目实战 搭建 MyBatis 框架 01-14
java·tomcat·mybatis
码不停蹄的玄黓1 天前
SpringBoot 全局异常处理器实现
java·spring boot·后端