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());开启该协程
相关推荐
沐浴露z几秒前
【微服务】基本概念介绍
java·微服务
Z3r4y30 分钟前
【代码审计】RuoYi-4.7.3&4.7.8 定时任务RCE 漏洞分析
java·web安全·ruoyi·代码审计
Kuo-Teng2 小时前
LeetCode 160: Intersection of Two Linked Lists
java·算法·leetcode·职场和发展
Jooou2 小时前
Spring事务实现原理深度解析:从源码到架构全面剖析
java·spring·架构·事务
盖世英雄酱581362 小时前
commit 成功为什么数据只更新了部分?
java·数据库·后端
码上淘金3 小时前
在 YAML 中如何将 JSON 对象作为字符串整体赋值?——兼谈 Go Template 中的 fromJson 使用
java·golang·json
刘一说3 小时前
Spring Boot 应用的指标收集与监控体系构建指南
java·spring boot·后端
老友@4 小时前
Java Excel 导出:EasyExcel 使用详解
java·开发语言·excel·easyexcel·excel导出
Full Stack Developme4 小时前
java.net.http 包详解
java·http·.net