跳到主要内容

extime

简介

时间扩展类, 使用 class map 作为时间戳载体, 提供方便时间编译计算方法

说明

星期天: 0, 星期一: 1 ... 星期六: 6

时间字符串描述说明

    "yyyy": "year",
"MM": "mon",
"dd": "mday",
"HH": "hour",
"mm": "min",
"ss": "sec"

组件接口

extime.gs

函数原型函数作用
mixed diff(Time self, mixed t, bool pretty = false)计算时间距离
int get_time(Time self)获取时间戳
Time set_time(Time self, mixed t, string format = "HH:mm:ss")设置时间
Time set_year(Time self, int year)设置年份
Time set_month(Time self, int mon)设置月份
Time set_day(Time self, mixed day, string format = "YYYY.MM.dd")设置日期
Time set_hour(Time self, int hour)设置小时
Time set_min(Time self, int min)设置分钟
Time set_sec(Time self, int sec)设置秒
Time add_year(Time self, int num = 1)偏移年份
Time add_month(Time self, int num = 1)偏移月份
Time set_week_day(Time self, int wday)设置为该星期的星期几
Time set_next_week_day(Time self, int wday)设置接下来的星期几
Time add_day(Time self, int num = 1)偏移天数
Time add_hour(Time self, int num = 1)偏移小时
Time add_minute(Time self, int num = 1)偏移分钟
Time add_second(Time self, int num = 1)偏移秒
string format(Time self, string val = "yyyy.MM.DD HH:mm:ss")按照格式, 格式化字符串
Time parse_from_string(string time_des, string format = "yyyy.MM.dd HH:mm:ss")从字符串读取时间
string pretty_output_diff(int diff, array units = ["年", "月", "日", "小时", "分钟", "秒"])将时间间隔美化输出
string format(int t, string val = "yyyy.MM.DD HH:mm:ss")按照格式, 格式化字符串

样例

public void sample()
{
write(extime.this_monday().ctime(), "\n");
write(extime.next_monday().ctime(), "\n");
Time t = extime.new();
t.add_hour(-10);
printf("%s\n", t.ctime());
t.add_day(8);
printf("%s\n", t.ctime());
t.set_week_day(1);
t.set_next_week_day(1);
printf("next monday:%s\n", t.ctime());
t.add_month(1);
printf("%s\n", t.ctime());
t.add_year(1);
printf("%s\n", t.ctime());
t = extime.new("2022.12.15 12:05:33", "yyyy.MM.dd HH:mm:ss");
printf("%s\n", t.ctime());
t.set_time("13:22:15");
printf("%s\n", t.format());
printf("%s\n", extime.pretty_output_diff(1));
printf("%s\n", extime.pretty_output_diff(70));
printf("%s\n", extime.pretty_output_diff(3700));
printf("%s\n", extime.pretty_output_diff(87000));
printf("%s\n", extime.pretty_output_diff(87000 * 30));
printf("%s\n", extime.pretty_output_diff(87000 * 395));
printf("%s\n", t.diff(t.get_time() - 10000, true));
}