
1 package com.evian.utils
2 {
3 public class DateUtil
4 {
5 public static const MINUTE_IN_MILLISECONDS : Number = 60 * 1000;
6 public static const HOUR_IN_MILLISECONDS : Number = 60 * 60 * 1000;
7 public static const DAY_IN_MILLISECONDS : Number = 24 * 60 * 60 * 1000;
8 public static const WEEK_IN_MILLISECONDS : Number = 7 * 24 * 60 * 60 * 1000;
9 public static const MONTH_IN_MILLISECONDS : Number = 30 * 24 * 60 * 60 * 1000;
10 public static const YEAR_IN_MILLISECONDS : Number = 12 * 30 * 24 * 60 * 60 * 1000;
11 public static const CENTURY_IN_MILLISECONDS : Number = 100 * 12 * 30 * 24 * 60 * 60 * 1000;
12 public static const MILLENIUM_IN_MILLISECONDS : Number = 1000 * 100 * 12 * 30 * 24 * 60 * 60 * 1000;
13
14 public static function clearTime( date : Date ) : Date
15 {
16 date.date=1;
17 date.hours = 0;
18 date.minutes = 0;
19 date.seconds = 0;
20 date.milliseconds = 0;
21
22 return date;
23 }
24
25 public static function copyDate( date : Date ) : Date
26 {
27 return new Date( date.getTime() );
28 }
29
30 public static function setTime( date : Date, time : Number ) : Date
31 {
32 date.date = Math.ceil(time / (1000 * 60 * 60 *24));
33 date.hours = Math.floor(( time / (1000 * 60 * 60)) % 24);
34 date.minutes = Math.floor(( time / (1000 * 60)) % 60);
35 date.seconds = Math.floor(( time / 1000) % 60);
36 date.milliseconds = Math.floor( time % 1000);
37
38 return date;
39 }
40
41 public static function addTime( date : Date, time : Number ) : Date
42 {
43 date.milliseconds += time;
44
45 return date;
46 }
47 /**
48 * format to 00:00:00
49 */
50 public static function formatTimeString(hours:int,minutes:int,seconds:int):String
51 {
52 var h:String="";
53 var m:String="";
54 var s:String="";
55
56 h=hours>9?hours.toString():"0"+hours.toString();
57 m=minutes>9?minutes.toString():"0"+minutes.toString();
58 s=seconds>9?seconds.toString():"0"+seconds.toString();
59
60 return h+":"+m+":"+s;
61 }
62 /**
63 * format to 00:00
64 */
65 public static function formatTimeToHour(hours:int,minutes:int,seconds:int):String
66 {
67
68 var m:String="";
69 var s:String="";
70
71 minutes+=hours*60;
72 m=minutes>9?minutes.toString():"0"+minutes.toString();
73 s=seconds>9?seconds.toString():"0"+seconds.toString();
74
75 return m+":"+s;
76 }
77 /**
78 * @param seconds 秒
79 * format to 00:00:00
80 */
81 public static function formatTimeToString2(seconds:int):String
82 {
83 var hour:int=seconds/3600;
84 var minutes:int=seconds/60%60;
85 var scecond:int=seconds-hour*3600-minutes*60;
86
87 return formatTimeString(hour,minutes,scecond);
88
89 }
90 }
91 }

【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· dotnet 源代码生成器分析器入门
· 官方的 MCP C# SDK:csharp-sdk
· 一款 .NET 开源、功能强大的远程连接管理工具,支持 RDP、VNC、SSH 等多种主流协议!
· 一步一步教你部署ktransformers,大内存单显卡用上Deepseek-R1
· 一次Java后端服务间歇性响应慢的问题排查记录