123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package com.emato.biz.util;
- import java.sql.Timestamp;
- import java.text.SimpleDateFormat;
- /**
- * 时间工具类
- *
- * @author frankeleyn
- * @email lvjian@qhdswl.com
- * @date 2023/4/10 16:21
- */
- public class DateUtil {
- /**
- * 格式化时间戳
- *
- * @param timestampStr
- * @param format
- * @return
- */
- public static String dateFormat(String timestampStr, String format) {
- long timestamp = Long.parseLong(timestampStr);
- Timestamp ts = new Timestamp(timestamp);
- SimpleDateFormat sdf = new SimpleDateFormat(format);
- return sdf.format(ts);
- }
- /**
- * 计算时间戳相差多少小时
- *
- * @param timestamp1
- * @param timestamp2
- * @return
- */
- public static long getHourBetweenTimesStamp(String timestamp1, String timestamp2) {
- long diff = (Long.parseLong(timestamp2) - Long.parseLong(timestamp1)) / (1000 * 60 *60);
- return diff;
- }
- }
|