Welcome

首页 / 软件开发 / JAVA / Java实现字符串的日期格式转时间戳

Java实现字符串的日期格式转时间戳

    public static long StringDateToStamp(String dateString){
        long _timestamp_=0;
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = dateFormat.parse(dateString);
            Timestamp timestamp = new Timestamp(date.getTime());
            _timestamp_=timestamp.getTime()/1000;
        } catch (ParseException e) {
            _timestamp_=0;
        }
        return _timestamp_;
    }