Java工具类方法 时间字符串转成时间戳 2022-10-08 10:47:08 yyyy-MM-dd HH:mm:ss 返回时间戳 1665290918
- public long gettimeStemp(String time, String format) {
-
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- if (!"".equals(format)) {
- simpleDateFormat = new SimpleDateFormat(format);
- }
-
- long timeStemp = 0;
- try {
-
- Date date = simpleDateFormat.parse(time);
-
- timeStemp = date.getTime();
-
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return timeStemp;
- }