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());开启该协程
相关推荐
郑州光合科技余经理20 小时前
同城系统海外版:一站式多语种O2O系统源码
java·开发语言·git·mysql·uni-app·go·phpstorm
一只乔哇噻20 小时前
java后端工程师+AI大模型开发进修ing(研一版‖day60)
java·开发语言·人工智能·学习·语言模型
Dolphin_Home20 小时前
笔记:SpringBoot静态类调用Bean的2种方案(小白友好版)
java·spring boot·笔记
MetaverseMan21 小时前
Java虚拟线程实战
java
浪潮IT馆1 天前
Tomcat运行war包的问题分析与解决步骤
java·tomcat
悟能不能悟1 天前
Caused by: java.sql.SQLException: ORA-28000: the account is locked怎么处理
java·开发语言
_院长大人_1 天前
MyBatis Plus 分批查询优化实战:优雅地解决 IN 参数过多问题(实操)
java·mybatis
C雨后彩虹1 天前
机器人活动区域
java·数据结构·算法·华为·面试
a3158238061 天前
Android Framework开发知识点整理
android·java·linux·服务器·framework·android源码开发