/** * 将时间字符串转为Date类型 * <p>time格式为yyyy-MM-dd HH:mm:ss</p> * * @param time 时间字符串 * @return Date类型 */ public static Date string2Date(String time) { return string2Date(time, DEFAULT_FORMAT); }
/** * 获取年份中的第几周 * <p>注意:国外周日才是新的一周的开始</p> * <p>time格式为format</p> * * @param time 时间字符串 * @param format 时间格式 * @return 1...54 */ public static int getWeekOfYear(String time, DateFormat format) { return getWeekOfYear(string2Date(time, format)); }
/** * 判断是否闰年 * <p>time格式为format</p> * * @param time 时间字符串 * @param format 时间格式 * @return {@code true}: 闰年<br>{@code false}: 平年 */ public static boolean isLeapYear(String time, DateFormat format) { return isLeapYear(string2Date(time, format)); }
/** * 获取月份中的第几周 * <p>注意:国外周日才是新的一周的开始</p> * <p>time格式为format</p> * * @param time 时间字符串 * @param format 时间格式 * @return 1...5 */ public static int getWeekOfMonth(String time, DateFormat format) { return getWeekOfMonth(string2Date(time, format)); }
/** * 获取生肖 * <p>time格式为yyyy-MM-dd HH:mm:ss</p> * * @param time 时间字符串 * @return 生肖 */ public static String getChineseZodiac(String time) { return getChineseZodiac(string2Date(time, DEFAULT_FORMAT)); }
/** * 获取月份中的第几周 * <p>注意:国外周日才是新的一周的开始</p> * <p>time格式为yyyy-MM-dd HH:mm:ss</p> * * @param time 时间字符串 * @return 1...5 */ public static int getWeekOfMonth(String time) { return getWeekOfMonth(string2Date(time, DEFAULT_FORMAT)); }
/** * 获取年份中的第几周 * <p>注意:国外周日才是新的一周的开始</p> * <p>time格式为yyyy-MM-dd HH:mm:ss</p> * * @param time 时间字符串 * @return 1...54 */ public static int getWeekOfYear(String time) { return getWeekOfYear(string2Date(time, DEFAULT_FORMAT)); }
/** * 获取中式星期 * <p>time格式为yyyy-MM-dd HH:mm:ss</p> * * @param time 时间字符串 * @return 中式星期 */ public static String getChineseWeek(String time) { return getChineseWeek(string2Date(time, DEFAULT_FORMAT)); }
/** * 获取美式星期 * <p>time格式为format</p> * * @param time 时间字符串 * @param format 时间格式 * @return 美式星期 */ public static String getUSWeek(String time, DateFormat format) { return getUSWeek(string2Date(time, format)); }
/** * 获取星座 * <p>time格式为format</p> * * @param time 时间字符串 * @param format 时间格式 * @return 生肖 */ public static String getZodiac(String time, DateFormat format) { return getZodiac(string2Date(time, format)); }
/** * 判断是否闰年 * <p>time格式为yyyy-MM-dd HH:mm:ss</p> * * @param time 时间字符串 * @return {@code true}: 闰年<br>{@code false}: 平年 */ public static boolean isLeapYear(String time) { return isLeapYear(string2Date(time, DEFAULT_FORMAT)); }
/** * 获取中式星期 * <p>time格式为format</p> * * @param time 时间字符串 * @param format 时间格式 * @return 中式星期 */ public static String getChineseWeek(String time, DateFormat format) { return getChineseWeek(string2Date(time, format)); }
/** * 获取美式星期 * <p>time格式为yyyy-MM-dd HH:mm:ss</p> * * @param time 时间字符串 * @return 美式星期 */ public static String getUSWeek(String time) { return getUSWeek(string2Date(time, DEFAULT_FORMAT)); }
/** * 获取生肖 * <p>time格式为format</p> * * @param time 时间字符串 * @param format 时间格式 * @return 生肖 */ public static String getChineseZodiac(String time, DateFormat format) { return getChineseZodiac(string2Date(time, format)); }
/** * 获取星座 * <p>time格式为yyyy-MM-dd HH:mm:ss</p> * * @param time 时间字符串 * @return 生肖 */ public static String getZodiac(String time) { return getZodiac(string2Date(time, DEFAULT_FORMAT)); }
/** * 获取星期索引 * <p>注意:周日的Index才是1,周六为7</p> * <p>time格式为format</p> * * @param time 时间字符串 * @param format 时间格式 * @return 1...7 * @see Calendar#SUNDAY * @see Calendar#MONDAY * @see Calendar#TUESDAY * @see Calendar#WEDNESDAY * @see Calendar#THURSDAY * @see Calendar#FRIDAY * @see Calendar#SATURDAY */ public static int getWeekIndex(String time, DateFormat format) { return getWeekIndex(string2Date(time, format)); }
/** * 获取星期索引 * <p>注意:周日的Index才是1,周六为7</p> * <p>time格式为yyyy-MM-dd HH:mm:ss</p> * * @param time 时间字符串 * @return 1...7 * @see Calendar#SUNDAY * @see Calendar#MONDAY * @see Calendar#TUESDAY * @see Calendar#WEDNESDAY * @see Calendar#THURSDAY * @see Calendar#FRIDAY * @see Calendar#SATURDAY */ public static int getWeekIndex(String time) { return getWeekIndex(string2Date(time, DEFAULT_FORMAT)); }
@Test public void string2Date() throws Exception { assertEquals(timeDate, TimeUtils.string2Date(timeString)); assertEquals(timeDate, TimeUtils.string2Date(timeStringFormat, mFormat)); }