java String时间转为时间戳

import java.text.SimpleDateFormat;
import java.util.Date;


public void testString2Date() {
        String startDate = "2017-08-15";
        String endDate = "2017-08-15";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        int startDay = 0;
        int endDay = 0;

        try {
            Date dateStart = format.parse(startDate);
            Date datEnd = format.parse(endDate);

            startDay = (int) (dateStart.getTime() / 1000);
            endDay = (int) (datEnd.getTime() / 1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.err.println(startDay);
        System.err.println(endDay);
    }

posted @ 2017-08-15 15:32  whendream  阅读(25256)  评论(0编辑  收藏  举报