1+ // ==========================================================================================
2+ // GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利
3+ // GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights
4+ // 均受中华人民共和国及相关国际法律法规保护。
5+ // are protected by the laws of the People's Republic of China and relevant international regulations.
6+ //
7+ // 使用本项目须严格遵守相应法律法规及开源许可证之规定。
8+ // Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses.
9+ //
10+ // 本项目采用 MIT 许可证与 Apache License 2.0 双许可证分发,
11+ // This project is dual-licensed under the MIT License and Apache License 2.0,
12+ // 完整许可证文本请参见源代码根目录下的 LICENSE 文件。
13+ // please refer to the LICENSE file in the root directory of the source code for the full license text.
14+ //
15+ // 禁止利用本项目实施任何危害国家安全、破坏社会秩序、
16+ // It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order,
17+ // 侵犯他人合法权益等法律法规所禁止的行为!
18+ // or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations!
19+ // 因基于本项目二次开发所产生的一切法律纠纷与责任,
20+ // Any legal disputes and liabilities arising from secondary development based on this project
21+ // 本项目组织与贡献者概不承担。
22+ // shall be borne solely by the developer; the project organization and contributors assume no responsibility.
23+ //
24+ // GitHub 仓库:https://github.com/GameFrameX
25+ // GitHub Repository: https://github.com/GameFrameX
26+ // Gitee 仓库:https://gitee.com/GameFrameX
27+ // Gitee Repository: https://gitee.com/GameFrameX
28+ // 官方文档:https://gameframex.doc.alianblank.com/
29+ // Official Documentation: https://gameframex.doc.alianblank.com/
30+ // ==========================================================================================
31+
32+ using System ;
33+
34+ namespace GameFrameX . Runtime
35+ {
36+ public partial class TimerHelper
37+ {
38+ /// <summary>
39+ /// 获取当前UTC时间,格式为HHmmss的字符串
40+ /// </summary>
41+ /// <returns>返回一个6位字符串,表示当前UTC时间。例如:143045表示14:30:45</returns>
42+ /// <remarks>
43+ /// 此方法将当前UTC时间转换为6位时间字符串:
44+ /// - 前2位表示小时(24小时制)
45+ /// - 中间2位表示分钟
46+ /// - 最后2位表示秒
47+ /// 使用DateTime.UtcNow获取UTC时间
48+ /// </remarks>
49+ public static string CurrentTimeWithUtcFullString ( )
50+ {
51+ return DateTime . UtcNow . ToString ( "HHmmss" ) ;
52+ }
53+
54+ /// <summary>
55+ /// 获取当前本地时间,格式为HHmmss的字符串
56+ /// </summary>
57+ /// <returns>返回一个6位字符串,表示当前本地时间。例如:143045表示14:30:45</returns>
58+ /// <remarks>
59+ /// 此方法将当前本地时间转换为6位时间字符串:
60+ /// - 前2位表示小时(24小时制)
61+ /// - 中间2位表示分钟
62+ /// - 最后2位表示秒
63+ /// 使用DateTime.Now获取本地时间
64+ /// </remarks>
65+ public static string CurrentTimeWithLocalFullString ( )
66+ {
67+ return DateTime . Now . ToString ( "HHmmss" ) ;
68+ }
69+
70+ /// <summary>
71+ /// 获取当前UTC时间,格式为HHmmss的整数
72+ /// </summary>
73+ /// <returns>返回一个6位整数,表示当前UTC时间。例如:143045表示14:30:45</returns>
74+ /// <remarks>
75+ /// 此方法将当前UTC时间转换为6位整数:
76+ /// - 前2位表示小时(24小时制)
77+ /// - 中间2位表示分钟
78+ /// - 最后2位表示秒
79+ /// 内部调用CurrentTimeWithUtcFullString()获取字符串后转换为整数
80+ /// </remarks>
81+ public static int CurrentTimeWithUtcTime ( )
82+ {
83+ return Convert . ToInt32 ( CurrentTimeWithUtcFullString ( ) ) ;
84+ }
85+
86+ /// <summary>
87+ /// 获取当前本地时间,格式为HHmmss的整数
88+ /// </summary>
89+ /// <returns>返回一个6位整数,表示当前本地时间。例如:143045表示14:30:45</returns>
90+ /// <remarks>
91+ /// 此方法将当前本地时间转换为6位整数:
92+ /// - 前2位表示小时(24小时制)
93+ /// - 中间2位表示分钟
94+ /// - 最后2位表示秒
95+ /// 内部调用CurrentTimeWithLocalFullString()获取字符串后转换为整数
96+ /// </remarks>
97+ public static int CurrentTimeWithLocalTime ( )
98+ {
99+ return Convert . ToInt32 ( CurrentTimeWithLocalFullString ( ) ) ;
100+ }
101+
102+ /// <summary>
103+ /// 获取当前本地时区时间的自定义格式字符串
104+ /// </summary>
105+ /// <param name="format">时间格式字符串,默认为"yyyy-MM-dd HH:mm:ss.fff K"</param>
106+ /// <returns>返回指定格式的本地时间字符串。例如默认格式返回:"2023-12-25 14:30:45.123 +08:00"</returns>
107+ /// <remarks>
108+ /// 此方法允许自定义时间格式字符串:
109+ /// - 默认格式包含年月日时分秒毫秒和时区信息
110+ /// - 可以通过format参数指定其他格式
111+ /// - 使用DateTime.Now获取本地时间
112+ /// 支持标准的.NET日期时间格式说明符
113+ /// </remarks>
114+ public static string CurrentDateTimeWithFormat ( string format = "yyyy-MM-dd HH:mm:ss.fff K" )
115+ {
116+ return DateTime . Now . ToString ( format ) ;
117+ }
118+
119+ /// <summary>
120+ /// 获取当前UTC时区时间的自定义格式字符串
121+ /// </summary>
122+ /// <param name="format">时间格式字符串,默认为"yyyy-MM-dd HH:mm:ss.fff K"</param>
123+ /// <returns>返回指定格式的UTC时间字符串。例如默认格式返回:"2023-12-25 06:30:45.123 +00:00"</returns>
124+ /// <remarks>
125+ /// 此方法允许自定义UTC时间格式字符串:
126+ /// - 默认格式包含年月日时分秒毫秒和时区信息
127+ /// - 可以通过format参数指定其他格式
128+ /// - 使用DateTime.UtcNow获取UTC时间
129+ /// 支持标准的.NET日期时间格式说明符
130+ /// </remarks>
131+ public static string CurrentDateTimeWithUtcFormat ( string format = "yyyy-MM-dd HH:mm:ss.fff K" )
132+ {
133+ return DateTime . UtcNow . ToString ( format ) ;
134+ }
135+
136+ /// <summary>
137+ /// 获取当前UTC时间
138+ /// </summary>
139+ /// <returns>当前UTC时间</returns>
140+ /// <remarks>
141+ /// 此方法返回当前的UTC时间(协调世界时)
142+ /// 与本地时间相比会有时区偏移
143+ /// 主要用于需要统一时间标准的场景
144+ /// </remarks>
145+ public static DateTime GetUtcNow ( )
146+ {
147+ return DateTime . UtcNow ;
148+ }
149+
150+ /// <summary>
151+ /// 获取当前时间
152+ /// </summary>
153+ /// <returns>当前时间</returns>
154+ /// <remarks>
155+ /// 此方法返回当前的本地时间
156+ /// 会根据系统设置的时区自动调整
157+ /// 主要用于需要显示本地时间的场景
158+ /// </remarks>
159+ public static DateTime GetNow ( )
160+ {
161+ return DateTime . Now ;
162+ }
163+ }
164+ }
0 commit comments