首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

java获取当前时间戳转换

package com.pts.peoplehui.utils; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; public class DateUtils { public static String getTodayDateTime() { SimpleDateFormat format = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”, Locale.getDefault()); return format.format(new Date()); } /** * 掉此方法输入所要转换的时间输入例如(”2014年06月14日16时09分00秒”)返回时间戳 * * @param time * @return */ public String data(String time) { SimpleDateFormat sdr = new SimpleDateFormat(“yyyy年MM月dd日HH时mm分ss秒”, Locale.CHINA); Date date; String times = null; try { date = sdr.parse(time); long l = date.getTime(); String stf = String.valueOf(l); times = stf.substring(0, 10); } catch (Exception e) { e.printStackTrace(); } return times; } public static String getTodayDateTimes() { SimpleDateFormat format = new SimpleDateFormat(“MM月dd日”, Locale.getDefault()); return format.format(new Date()); } /** * 获取当前时间 * * @return */ public static String getCurrentTime_Today() { SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd-HH-mm-ss”); return sdf.format(new java.util.Date()); } /** * 调此方法输入所要转换的时间输入例如(”2014-06-14-16-09-00″)返回时间戳 * * @param time * @return */ public static String dataOne(String time) { SimpleDateFormat sdr = new SimpleDateFormat(“yyyy-MM-dd-HH-mm-ss”, Locale.CHINA); Date date; String times = null; try { date = sdr.parse(time); long l = date.getTime(); String stf = String.valueOf(l); times = stf.substring(0, 10); } catch (Exception e) { e.printStackTrace();

02

获取指定日期的前一天23:59:59

/**  * 获得指定日期的前一天的23:59:59  *  * @param specifiedDay 指定日期  * @return 前一天日期 23:59:59  */ public static Date getSpecifiedDayBefore(Date specifiedDay) {     if (null == specifiedDay) {         return null;     }     Date newDate = null;     try {         Calendar c = Calendar.getInstance();         c.setTime(specifiedDay);         int day = c.get(Calendar.DATE);         c.set(Calendar.DATE, day - 1);         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");         String newDateStr = simpleDateFormat.format(c.getTime()) + " 23:59:59";         SimpleDateFormat newSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");         newDate = newSimpleDateFormat.parse(newDateStr);     } catch (ParseException e) {         log.info("日期转换错误" + e.getMessage());     }     return newDate; }

01
领券