| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /**
- * @包名称 com.sagacloud.common
- * @文件名 DateUtil.java
- * @创建者 wanghailong
- * @邮箱 wanghailong@persagy.com
- * @修改描述
- */
- package com.persagy.old.common;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- /**
- * 功能描述: 日期工具类
- * @类型名称 DateUtil
- * @创建者 wanghailong
- * @邮箱 wanghailong@persagy.com
- * @修改描述
- */
- public class DateUtil {
- public static String sdfHour = "yyyyMMddHH";
- public static String getNowTimeStr() {
- SimpleDateFormat sdf = new SimpleDateFormat(CommonConst.date_format_save);
- return sdf.format(new Date());
- }
-
- /**
- * 获取当前的UTC时间,精确到毫秒
- */
- public static Long getUtcTimeNow(){
- Date dateNow = new Date();
- Long lRes = dateNow.getTime();
- return lRes;
- }
- /**
- * 转换时间格式
- * @param dateStr
- * @param fromDateFormat
- * @param toDateFormat
- * @return
- * @throws ParseException
- */
- public static String transferDateFormat(String dateStr, String fromDateFormat, String toDateFormat) throws ParseException {
- SimpleDateFormat fromSdf = new SimpleDateFormat(fromDateFormat);
- SimpleDateFormat toSdf = new SimpleDateFormat(toDateFormat);
- return toSdf.format(fromSdf.parse(dateStr));
- }
-
- public static Date parseDate(String pattern, String str) throws ParseException {
- Date date = new SimpleDateFormat(pattern).parse(str);
- return date;
- }
- public static String formatStr(String pattern, Date date) {
- String str = new SimpleDateFormat(pattern).format(date);
- return str;
- }
- }
|