public abstract class Times extends Object
构造器和说明 |
---|
Times() |
限定符和类型 | 方法和说明 |
---|---|
static long |
ams(String ds)
根据默认时区计算时间字符串的绝对毫秒数
|
static long |
ams(String ds,
TimeZone tz)
根据字符串得到相对于 "UTC 1970-01-01 00:00:00" 的绝对毫秒数。
|
static Calendar |
C(Date d)
根据日期对象得到时间
|
static Calendar |
C(long ms)
根据毫秒数得到时间
|
static Calendar |
C(String ds)
根据字符串得到时间
如果你输入了格式为 "yyyy-MM-dd HH:mm:ss"
那么会匹配到秒
如果你输入格式为 "yyyy-MM-dd"
相当于你输入了 "yyyy-MM-dd 00:00:00"
|
static int |
countLeapYear(int year)
判断某年(不包括自己)之前有多少个闰年
|
static Date |
D(long ms)
根据毫秒数得到时间
|
static Date |
D(String ds)
根据字符串得到时间对象
|
static int |
D1970(int yy,
int MM,
int dd)
计算一个给定日期,距离 1970 年 1 月 1 日有多少天
|
static String |
format(DateFormat fmt,
Date d)
以给定的时间格式来安全的对时间进行格式化,并返回格式化后所对应的字符串
|
static String |
format(String fmt,
Date d)
以给定的时间格式来安全的对时间进行格式化,并返回格式化后所对应的字符串
|
static String |
formatForRead(Date d)
将一个时间格式化成容易被人类阅读的格式
如果 1 分钟内,打印 Just Now
如果 1 小时内,打印多少分钟
如果 1 天之内,打印多少小时之前
如果是今年之内,打印月份和日期
否则打印月份和年
|
static String |
fromMillis(long mi)
一段时间长度的毫秒数转换为一个时间长度的字符串
1000 -> 1S
120000 - 2M
|
static String |
fromMillisCN(long mi)
fromMillis的中文版本
1000 -> 1秒
120000 - 2分
|
static boolean |
leapYear(int year)
判断一年是否为闰年,如果给定年份小于1全部为 false
|
static int |
ms()
返回当前时间在一天中的毫秒数
|
static int |
ms(Calendar c)
返回时间对象在一天中的毫秒数
|
static long |
ms(Date d)
返回时间对象在一天中的毫秒数
|
static long |
ms(String ds,
TimeZone tz)
已过时。
since 1.b.49 util 1.b.51
|
static String |
mss(int ms)
根据一个当天的绝对毫秒数,得到一个时间字符串,格式为 "HH:mm:ss.EEE"
|
static Date |
now()
返回服务器当前时间
|
static Date |
parse(DateFormat fmt,
String s)
以给定的时间格式来安全的解析时间字符串,并返回解析后所对应的时间对象
|
static Date |
parse(String fmt,
String s)
以给定的时间格式来安全的解析时间字符串,并返回解析后所对应的时间对象
|
static Date |
parseq(DateFormat fmt,
String s)
以给定的时间格式来安全的解析时间字符串,并返回解析后所对应的时间对象(包裹RuntimeException)
|
static Date |
parseq(String fmt,
String s)
以给定的时间格式来安全的解析时间字符串,并返回解析后所对应的时间对象(包裹RuntimeException)
|
static String |
sD(Date d)
把时间转换成格式为 yyyy-MM-dd 的字符串
|
static String |
sDT(Date d)
把时间转换成格式为 yyyy-MM-dd HH:mm:ss 的字符串
|
static String |
sDTms(Date d)
把时间转换成格式为 y-M-d H:m:s.S 的字符串
|
static String |
sDTms2(Date d)
把时间转换成格式为 yy-MM-dd HH:mm:ss.SSS 的字符串
|
static int |
sec()
返回当前时间在一天中的秒数
|
static int |
sec(Date d)
返回时间对象在一天中的秒数
|
static String |
secs(int sec)
根据一个当天的绝对秒数,得到一个时间字符串,格式为 "HH:mm:ss"
|
static String |
sT(int sec)
将一个秒数(天中),转换成一个格式为 HH:mm:ss 的字符串
|
static String |
sTmin(int sec)
将一个秒数(天中),转换成一个格式为 HH:mm 的字符串(精确到分钟)
|
static int[] |
T(int sec)
将一个秒数(天中),转换成一个如下格式的数组:
[0-23][0-59[-059]
|
static int |
T(String ts)
将一个时间字符串,转换成一个一天中的绝对秒数
|
static long |
toMillis(String tstr)
方便的把时间换算成毫秒数
支持几个单位, s(秒), m(分钟), h(小时), d(天)
比如:
100s -> 100000
2m -> 120000 3h -> 10800000 |
static Date[] |
week(int off)
以本周为基础获得某一周的时间范围
|
static Date[] |
week(long base,
int off)
以某周为基础获得某一周的时间范围
|
static Date[] |
weeks(int offL,
int offR)
以本周为基础获得时间范围
|
static Date[] |
weeks(long base,
int offL,
int offR)
按周获得某几周周一 00:00:00 到周六 的时间范围
它会根据给定的 offL 和 offR 得到一个时间范围
对本函数来说 week(-3,-5) 和 week(-5,-3) 是一个意思
|
public static final long T_1S
public static final long T_1M
public static final long T_1H
public static final long T_1D
public static boolean leapYear(int year)
year
- 年份,比如 2012 就是二零一二年public static int countLeapYear(int year)
year
- 年份,比如 2012 就是二零一二年public static int[] T(int sec)
[0-23][0-59[-059]
sec
- 秒数public static int T(String ts)
ts
- 时间字符串,符合格式 "HH:mm:ss" 或者 "HH:mm"public static Date now()
public static long ams(String ds)
ds
- 时间字符串ams(String, TimeZone)
public static long ams(String ds, TimeZone tz)
yyyy-MM-dd HH:mm:ss yyyy-MM-dd HH:mm:ss.SSS yy-MM-dd HH:mm:ss; yy-MM-dd HH:mm:ss.SSS; yyyy-MM-dd; yy-MM-dd; HH:mm:ss; HH:mm:ss.SSS;时间字符串后面可以跟 +8 或者 +8:00 表示 GMT+8:00 时区。 同理 -9 或者 -9:00 表示 GMT-9:00 时区
ds
- 时间字符串tz
- 你给定的时间字符串是属于哪个时区的_P_TIME
public static long ms(String ds, TimeZone tz)
public static long ms(Date d)
d
- 时间对象public static int ms(Calendar c)
c
- 时间对象public static int ms()
public static String mss(int ms)
ms
- 当天的绝对毫秒数public static String secs(int sec)
ms
- 当天的绝对秒数public static int sec(Date d)
d
- 时间对象public static int sec()
public static Date D(String ds)
ds
- 时间字符串ams(String)
public static int D1970(int yy, int MM, int dd)
yy
- 年,比如 1999,或者 43MM
- 月,一月为 1,十二月为 12dd
- 日,每月一号为 1public static Date D(long ms)
ms
- 时间的毫秒数public static Calendar C(String ds)
如果你输入了格式为 "yyyy-MM-dd HH:mm:ss" 那么会匹配到秒 如果你输入格式为 "yyyy-MM-dd" 相当于你输入了 "yyyy-MM-dd 00:00:00"
ds
- 时间字符串public static Calendar C(long ms)
ms
- 时间的毫秒数public static String sDTms(Date d)
d
- 时间对象public static String sDTms2(Date d)
d
- 时间对象public static String sDT(Date d)
d
- 时间对象public static String sD(Date d)
d
- 时间对象public static String sT(int sec)
sec
- 秒数public static String sTmin(int sec)
sec
- 秒数public static Date[] week(int off)
off
- 从本周偏移几周, 0 表示本周,-1 表示上一周,1 表示下一周org.nutz.ztask.util.ZTasks#weeks(long, int, int)
public static Date[] week(long base, int off)
base
- 基础时间,毫秒off
- 从本周偏移几周, 0 表示本周,-1 表示上一周,1 表示下一周org.nutz.ztask.util.ZTasks#weeks(long, int, int)
public static Date[] weeks(int offL, int offR)
offL
- 从本周偏移几周, 0 表示本周,-1 表示上一周,1 表示下一周offR
- 从本周偏移几周, 0 表示本周,-1 表示上一周,1 表示下一周org.nutz.ztask.util.ZTasks#weeks(long, int, int)
public static Date[] weeks(long base, int offL, int offR)
它会根据给定的 offL 和 offR 得到一个时间范围
对本函数来说 week(-3,-5) 和 week(-5,-3) 是一个意思
base
- 基础时间,毫秒offL
- 从本周偏移几周, 0 表示本周,-1 表示上一周,1 表示下一周offR
- 从本周偏移几周, 0 表示本周,-1 表示上一周,1 表示下一周public static String formatForRead(Date d)
如果 1 分钟内,打印 Just Now 如果 1 小时内,打印多少分钟 如果 1 天之内,打印多少小时之前 如果是今年之内,打印月份和日期 否则打印月份和年
d
- public static String format(DateFormat fmt, Date d)
fmt
- 时间格式d
- 时间对象public static String format(String fmt, Date d)
fmt
- 时间格式d
- 时间对象public static Date parseq(DateFormat fmt, String s)
fmt
- 时间格式s
- 时间字符串public static Date parseq(String fmt, String s)
fmt
- 时间格式s
- 时间字符串public static Date parse(DateFormat fmt, String s) throws ParseException
fmt
- 时间格式s
- 日期时间字符串ParseException
public static Date parse(String fmt, String s) throws ParseException
fmt
- 时间格式s
- 日期时间字符串ParseException
public static long toMillis(String tstr)
tstr
- public static String fromMillis(long mi)
mi
- 毫秒数public static String fromMillisCN(long mi)
mi
- 毫秒数Copyright © 2016. All rights reserved.