获取日期和时间

来源:互联网 发布:好听的网络歌曲2015 编辑:程序博客网 时间:2024/04/27 13:43

1 获取当前年,月,日
年月日的格式:yyyy-M-d 2016年3月13日
年月日的格式为: yyyy-MM-dd 2016年03月13日

         Date date = new Date();        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d");        String currentDate = sdf.format(date);         return currentDate;

2 获取当前时间 年月日时分

            Date date = Calendar.getInstance().getTime();            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");            String result = sdf.format(date);
0 0
原创粉丝点击