时间格式转换

//时间戳转日期20220406
public static String parseDateToStr(Date time, String timeFormat) {
        DateFormat dateFormat = new SimpleDateFormat(timeFormat);
        return dateFormat.format(time);
}

//获取当天的开始时间
public static Long getNowDayStartTime(Date dateParam) {
        String startTime = DateFormatUtils.format(dateParam, "yyyy-MM-dd 00:00:00");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = simpleDateFormat.parse(startTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date.getTime();
}

//获取当天的结束时间
public static Long getNowDayEndTime(Date dateParam) {
        String endTime = DateFormatUtils.format(dateParam, "yyyy-MM-dd 23:59:59");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = simpleDateFormat.parse(endTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date.getTime();
}
public static Date getDayEnd() {
        Calendar cal = Calendar.getInstance();
        cal.set(11, 23);
        cal.set(12, 59);
        cal.set(13, 59);
        return cal.getTime();
}

你可能感兴趣的:(java,c#,javascript)