美文网首页
java获取系统时间

java获取系统时间

作者: 票务系统曾坪 | 来源:发表于2018-11-26 14:02 被阅读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;

    }

    相关文章

      网友评论

          本文标题:java获取系统时间

          本文链接:https://www.haomeiwen.com/subject/hgkbqqtx.html