zoukankan      html  css  js  c++  java
  • LocalDate的使用

    LocalDate的一些使用方法

    今天半天的时间都用在了LocalDate上,然后呢,也是自己的第一次写博客。

    首先来看看会用上的方法吧。

    两个构造器,用的是静态工厂方法

    static   LocalTime now()

    构造一个表示当前日期的对象     如果直接输出这个对象的话,会是  年-月-日

    static  LocalTime of(int year,int month,int day)

    自己设置年月日

    int   getYear()

    int getMonthValue()

    int  getDayOfMonth()

    获取当前的年月日

    DayOfWeek   getDayOfWeek()

    得到这天是星期几,不过要用getValue方法来得到 1-7 的int值    星期1就是1   

    LocalDate   plusDays(int)    往后多少天,然后返回一个新的LocalDate对象

    LocalDate   minusDay(int) 往前 多少天

     下面是个例子,输出当前月的日历

     1  public static void main(String[] args) {
     2         LocalDate date = LocalDate.now();
     3         int month = date.getMonthValue();
     4         int today = date.getDayOfMonth();
     5         date = date.minusDays(today-1);
     6         DayOfWeek weekday = date.getDayOfWeek();
     7         int value = weekday.getValue();
     8 //        System.out.println("value的值:"+value);
     9         System.out.println("Mon Tue Wed Thu Fri Sat Sun");
    10         for (int i = 1;i<=value;i++){
    11 
    12             System.out.print("   ");
    13         }
    14         while(date.getMonthValue() ==month){
    15             System.out.printf("%3d",date.getDayOfMonth());
    16             if(date.getDayOfMonth()==today){
    17                 System.out.print("*");
    18             }else{
    19                 System.out.print(" ");
    20             }
    21             date = date.plusDays(1);
    22             if (date.getDayOfWeek().getValue()==1){
    23                 System.out.println();
    24             }
    25         }
    26             if(date.getDayOfWeek().getValue()!=1){
    27                 System.out.println();
    28             }
    29     }
    View Code
  • 相关阅读:
    plink:将bed文件转化为ped,map文件
    linux下查找某文件关键字(grep 函数)
    genetic model
    linux下设置默认路径
    vi怎么查找关键字
    有意思的undefined columns selected,源于read.table和read.csv
    练习2-2
    练习2-1
    排序算法之堆排序
    Java实现二叉树先序,中序,后序,层次遍历
  • 原文地址:https://www.cnblogs.com/LiuShuang-GoJava/p/10616093.html
Copyright © 2011-2022 走看看