zoukankan      html  css  js  c++  java
  • java字符串和时间转换

    import java.text.SimpleDateFormat; 
    import java.util.Date; 
    
    //将long字符串转换成格式时间输出 
    public class LongToString { 
      public static void main(String argsp[]){ 
        String time="1256006105375"; 
        Date date=new Date(Long.parseLong(time)); 
        SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
        time=formatter.format(date); 
        System.out.println(time); 
      } 
    } 

      

    //字符串转换成时间
    public class StringToDate { 
      public static void main(String argsp[]) throws Exception{ 
        String time="2010-11-20 11:10:10"; 
        Date date=null; 
        SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
        date=formatter.parse(time); 
        System.out.println(date); 
    } 
    

      

    //取得当前系统时间,返回yyyy-MM-dd HH:mm:ss字符串
    public class StringToDate { 
      public static void main(String argsp[]) throws Exception{   
        Date date=new Date(); 
        SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
        String time=formatter.format(date); 
        System.out.println(time); 
      } 
    } 
    

      

    //取得当前系统时间,返回 HH:mm:ss字符串
    public class StringToDate { 
      public static void main(String argsp[]) throws Exception{   
        Date date=new Date(); 
        SimpleDateFormat formatter=new SimpleDateFormat("HH:mm:ss"); 
        String time=formatter.format(date); 
        System.out.println(time); 
      } 
    } 
    

      

    //将20101125102503转换成2010-11-25 10:25:03输出
    public class StringToDate { 
      public static void main(String argsp[]) throws Exception{  
        String time="20101125102503"; 
        SimpleDateFormat formatter1=new SimpleDateFormat("yyyy-HH-dd HH:mm:ss"); 
        SimpleDateFormat formatter2=new SimpleDateFormat("yyyyHHddHHmmss"); 
        time=formatter1.format(formatter2.parse(time)); 
        System.out.println(time); 
      } 
    }
    

      

  • 相关阅读:
    HDU 3436 Queuejumpers
    POJ 3580 SuperMemo
    HDU 2871 Memory Control
    Android 实现显示文字的Gallery
    Android 使用地图
    Android 深入的研究一下蓝牙
    手机录制视频demo
    用android来实现图片的绘制以及旋转缩放案例分析
    TextView 自动滚动(跑马灯)
    Android腾讯微博客户端开发一:在下方的Tab的实现
  • 原文地址:https://www.cnblogs.com/SharkChilli/p/11645814.html
Copyright © 2011-2022 走看看