第一种方式:获取当前时间然后按照指定格式转换成String类型

        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Calendar cal = Calendar.getInstance();
        String date = dateFormat.format(cal.getTime());
        System.out.println(date);

第二种方式:获取当前时间然后按照指定格式转换成String类型

         String systemTime = new
SimpleDateFormat("yyyyMMddHHmmssSSS").format(new                  
Date(System.currentTimeMillis()));

将Sting类型转成指定的时间类型格式

        String data = "2021-02-24 24:21:00";
        SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd");
        String date = sdf.format (sdf.parse (data));
        System.out.println (date);

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信