java获取系统时间

2018-11-26  本文已影响0人  票务系统曾坪

//获取系统时间

    private  String getTime() {

        Time times = new Time("GMT+8");

        times.setToNow();

        int year = times.year;

        int month = times.month;

        int day = times.monthDay;

        int minute = times.minute;

        int hour = times.hour;

        int sec = times.second;

        String result = year + "-" + String.format("%02d", month) + "-" + String.format("%02d", day)

                + " " + String.format("%02d", hour) + ":" + String.format("%02d", minute) + ":" + String.format("%02d", sec);

        return result;

    }

private String getTime() {

    Date date = new Date();

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    String result = dateFormat.format(date);

    return result;

}

上一篇下一篇

猜你喜欢

热点阅读