Unity 时间格式 12小时制与24小时制

news/2024/9/23 4:20:03/

using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UniRx;

public class DisplayTime : MonoBehaviour
{
//时间文本显示
[SerializeField]
private TextMeshProUGUI _time;
private int _timeType = 0;

enum TimeType
{is24HourFormat,is12HourFormat,isError
}private static readonly string TAG = "DisplayTime";void Start()
{DataCenter.TimeFormat.Subscribe(i =>{Log.I(TAG, "Time select value:  " + i);if (i == 0){_timeType = (int)TimeType.is24HourFormat;}else if (i == 1){_timeType = (int)TimeType.is12HourFormat;}else if (i == 2){_timeType = (int)TimeType.isError;}}).AddTo(this);
}
private void Awake()
{StartCoroutine(UpdateTimeEverySecond());
}private void UpdateTime()
{DateTime currentTime = DateTime.Now;if (_timeType == (int)TimeType.is24HourFormat){// 24 小时制string timeIn24HourFormat = currentTime.ToString("HH:mm");_time.text = timeIn24HourFormat;}else if (_timeType == (int)TimeType.is12HourFormat){// 12 小时制int hour = currentTime.Hour;if (hour > 12) { hour = hour - 12; }string timeIn12HourFormat = hour + ":" + currentTime.ToString("mm");_time.text = timeIn12HourFormat;}else{_time.text = "--:--";}
}
private IEnumerator UpdateTimeEverySecond()
{while (true){UpdateTime();yield return new WaitForSeconds(1.0f);}
}

}


http://www.ppmy.cn/news/1436152.html

相关文章

FlinkCDC基础篇章1-安装使用

1、下载、安装Flink 下载地址: Downloads | Apache Flink --------具体环境参考官网-------- 解压:tar zxf flink-XXXX-bin-scala_XXX.tgz 启动应用:./bin/start-cluster.sh 可访问:http://127.0.0.1:8081/ 校验 启动客户端…

服务器渲染技术(JSPELJSTL)

目录 前言 一.JSP 1.基本介绍 3.page指令(常用) 4.JSP三种常用脚本 4.1 声明脚本 <%! code %> 4.2 表达式脚本 <% code %> 4.3 代码脚本 <% code %> 4.4 注释 <%-- 注释 --%> 5. JSP 内置对象 5.1 基本介绍 5.2 九个内置对象 6.JSP域对象 二…

考研日常记录(upd 24.4.24)

由于实在太无聊了 &#xff0c; 所以记录以下考研备考日常 &#xff0c; 增加一点成就感 &#xff0c; 获得一点前进动力。 文章目录 2024.4.18 周四课程情况&#xff1a;时间规划&#xff1a; 2024.4.19 周五课程情况&#xff1a;时间规划&#xff1a; 2024.4.20 周六2024.4.2…

理解Docker:基础镜像、Dockerfile和容器镜像

dcoker是什么&#xff1f; 如果你想安装一个vim编辑下文本&#xff0c;在不同环境里你得执行不同的命令。如果你想将自己写的代码部署到各个不同操作系统的服务器上&#xff0c;那依赖的软件和配置就更多了&#xff0c;需要针对每个环境单独写一套部署脚本&#xff0c;这是很麻…

Go的题目

文章目录 前置概念自旋同步原语是什么意思sync.Mutex不是自旋锁互斥锁和读写锁的区别 GMPgoroutine的调度策略golang线程模型简述从全局队列里获取goroutine简述从本地队列里获取goroutineGolang map是否并发/线程安全 前置概念 自旋 “自旋就是循环等待锁释放” 在Go语言&a…

el-table报错“Cannot read properties of undefined (reading ‘style‘)”解决

今天在用 el-table 的时候遇到这样一个报错&#xff0c;排查了好久才找到一点眉目。 Error in callback for immediate watcher “maxHeight”: "TypeError: Cannot read properties of undefined (reading ‘style’) 出现问题的原因 问题代码&#xff1a; <el-tab…

pymilvus创建多向量

pymilvus创建多向量 从 Milvus 2.4 开始&#xff0c;引入了多向量支持和混合搜索框架&#xff0c;单个collection可以支持10个向量字段。不同的向量字段可以表示不同的方面、不同的embedding模型甚至表征同一实体的不同数据模态。该功能在综合搜索场景中特别有用&#xff0c;例…

深入理解Spring Boot钩子函数

在软件开发中&#xff0c;Spring Boot已经成为了构建Java应用程序的首选框架之一。它简化了应用程序的开发过程&#xff0c;并提供了丰富的功能和扩展性。 Spring Boot的钩子函数&#xff08;Hook Functions&#xff09;是其核心特性之一&#xff0c;能够在应用程序的生命周期…