zoukankan      html  css  js  c++  java
  • 日期格式的转换

    注:转载自:https://www.cnblogs.com/-cyb/articles/Android_Date_format_Change.html

    java8中,使用LocalDate、LocalTime、LocalDateTime用来处理时间。

    //获取当前时间
     LocalDate today = LocalDate.now();
    
    //标准时间
    LocalDateTime lt = LocalDateTime.now();
    

      

    1、使用SimpleDateFormat

    Date d=new Date(); 
    
    SimpleDateFormat sdf=newSimpleDateFormat("YYYY-MM-DD : HH:MM:SS"); 
    
    sdf.format(d);    

    2、字符串转换日期类型

    String date="2019年02月13日";
    
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日");
    
    Date d=sdf.parse(date);
    

    3、毫秒转换成日期类型

    long l=System.currentTimeMillis();
    
    Date d=new Date(l);
    

    4、获取系统日期和时间,并转换成sql保存到数据库中

    Date d=new Date();    //获取当前系统的时间
     
    SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //格式化日期
    
    String dateStr = sdf.format(d);       //转为字符串	
    
    //使用RS更新数据库,仍然要用rs.updateString,而不是rs.updateDade。
    rs.updateString("regtime",dateStr);  //regtime字段为datetime类型的
    

    5、按照本地时区输出当前日期

    Date d = new Date();
    
    d.toLocaleString();
    

    6、数据库中的日期以年-月-日方式输出

    SimpleDateFormat sdf = new SimpleDateFormat(YYYY-MM-dd);
    
    String sqlStr = "select bookDate from roomBook where bookDate between '1993-4-10' and '2019-4-25'";
    
    df.format(rs.getDate("bookDate"));
    

    7、格式化小数

    DecimalFormat df = new DecimalFormat(",###.00");
       
    double aNumber = 111215198.289648989; 
    
    String result = df.format(aNumber); 
  • 相关阅读:
    iOS开发数据库篇—SQLite简单介绍
    iOS FMDatabase 本地数据库的创建和几个基本使用方法
    iOS开发-CoreMotion框架
    ios中陀螺仪CoreMotion的用法
    iOS摄像头和相册-UIImagePickerController-浅析
    iOS使用AVCaptureSession自定义相机
    在iOS上实现一个简单的日历控件
    iOS开发UI篇—Button基础
    在Virt-manager中使用snapshot功能
    Node.js学习
  • 原文地址:https://www.cnblogs.com/luhan777/p/10369844.html
Copyright © 2011-2022 走看看