码迷,mamicode.com
首页 > 其他好文 > 详细

时间格式转换

时间:2018-03-20 00:54:13      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:class   exce   out   print   当前时间   new   parse   led   rgs   

public static void main(String[] args) throws ParseException {
        
        SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd HH:mm:ss");// HH:24小时制
        String format2 = sdf.format(new Date());
        System.out.println(format2);//18-03-19 23:01:07
        
        SimpleDateFormat sdf2 = new SimpleDateFormat("yy-MM-dd");
        String str = sdf.format(new Date());//String类型时间:18-03-19 23:01:07
        System.out.println("String类型时间:"+str);
        
        Timestamp ts = new Timestamp(new Date().getTime());
        System.out.println("TimeStamp:"+ts);//TimeStamp:2018-03-19 23:01:07.442

       // 将当前时间前移两小时   求前移两小时后的时间
        Long now = System.currentTimeMillis();//18-03-19 23:01:07
        Long time2  = 1000*60*60*2L;//前移两小时
        Long start = now -time2;
        Date date3 = new Date();
        date3.setTime(start);
        String format = sdf.format(date3);
        System.out.println(format);//18-03-19 21:01:07
        
    }

 

时间格式转换

标签:class   exce   out   print   当前时间   new   parse   led   rgs   

原文地址:https://www.cnblogs.com/northern-light/p/8605797.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!