zoukankan      html  css  js  c++  java
  • Date

    时间

    世界标准时间 格林尼治 GMT

    现在原子钟     北京=世界标准时间+8小时

    1s=1000ms

    计算机时间原点1970.1.1.00:00:00 算C语言

    Date  精确到毫秒     java.util

    无参构造 现在时间 有参构造计算机原点+参数(毫秒)

    setTime 从时间原点开始 设置时间

    getTime() 获取当前时间的毫秒值 和System.currentTimeMillis() 一样

    SimpleDateFormat 对Dtae对象格式化 和解析 (化为想要的格式 转化后格式化为Date)

    格式化

    SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM--dd HH:mm;ss");

    sdf.fomat(date);

    解析

    String s="2048-01-01";

    SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM--dd");

    Date date=sdf.parse(s); 

    package com.yang.API.TimeClass;
    
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    public class MyDate {
        public static void main(String[] args) throws ParseException {
    //      无参构一个计算机现在的时间
            Date date=new Date();
            Date date1=new Date();
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    
    // 格式化Date类自带的时间表示格式 System.out.println(simpleDateFormat.format(date)); String time="2018王11-15 15:10:55"; SimpleDateFormat simpleDateFormat1=new SimpleDateFormat("yyyy王MM-dd HH:mm:ss"); date1=simpleDateFormat1.parse(time); System.out.println(date1); } }

      

     LocalDateTime() 获取时间    时间+日期  构造方法私有  

    静态方法 now() 获取当前时间  静态方法 of()按照指定时间获取一个LocalDateTime对象

     int get_______() 年月日时分秒  public DayOfWeek getDayOfWeek()周

     转换to______()

     

    格式 化和解析

    Jdk8  DateTimeFormatter

    package com.yang.API.TimeClass;
    
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.time.DateTimeException;
    import java.time.LocalDateTime;
    import java.time.format.DateTimeFormatter;
    import java.util.Date;
    
    public class MyDateTimeFormatter {
        public static void main(String[] args) throws ParseException {
    //      无参构一个计算机现在的时间
            LocalDateTime localDateTime=LocalDateTime.now();
    //DateTimeFoematter构造函数私有 DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("yyyy王MM-dd HH:mm:ss"); // 格式化LocalDateTime类自带的时间表示格式()
    System.out.println(dateTimeFormatter.format(localDateTime)); String time="2018王11-15 15:10:55"; //解析格式 是LocalDateTIme自带的 localDateTime=LocalDateTime.parse(time,dateTimeFormatter); System.out.println(localDateTime); }
    }

     LocalDateTime增加或者减少时间

    LocalDateTime自带格式化和解析方法 format(指定格式 DateTimeFormatter)  paser(准备解析字符串,DateTimeFormatter)

    plusYears(int ) Plus___s() 增加哪个时间段  参数为负数就是减      minus___s

    修改时间With___()

     时间间隔 Period  .between(LocalDate,LocalDate).get__(); 获得get省略的时间间隔最多精确到天 例如间隔年 ,getYears()

     Duration.between(LocalDate,LocalDate).to____();获取秒和毫秒;

  • 相关阅读:
    Protocol Buffer技术详解(语言规范)
    google protobuf 简单实例
    advStringGrid单元格文字垂直居中
    java中两个字符串如何比较大小
    List集合去除重复对象及equals()、hashCode()方法的作用
    Delphi中使用ActiveX的一些心得
    java List去重方式及效率对比
    Visual Studio Code 调整字体大小
    用最简单的例子实现jQuery图片即时上传
    Linux下绝对经典的命令
  • 原文地址:https://www.cnblogs.com/yang-qiu/p/15389050.html
Copyright © 2011-2022 走看看