zoukankan      html  css  js  c++  java
  • Java如何显示一年的周数?

    在Java中,如何查找一年中或一个月中的第几个星期?

    以下示例显示年份和月份的第几周。

    package com.yiibai;
    import java.util.*;
    
    public class DisplayWeekNumber {
        public static void main(String[] args) throws Exception {
            Date d1 = new Date();
            Calendar cl = Calendar.getInstance();
            cl.setTime(d1);
    
            System.out.println("today is " + cl.WEEK_OF_YEAR + " week of the year");
            System.out.println("today is a " + cl.DAY_OF_MONTH
                    + "month of the year");
            System.out.println("today is a " + cl.WEEK_OF_MONTH
                    + "week of the month");
        }
    }
    
    Java

    上述代码示例将产生以下结果。

    today is 3 week of the year
    today is a 5month of the year
    today is a 4week of the month
    
    Shell

    示例-2
    以下是一年中的一个月的一个例子。

    package com.yiibai;
    import java.util.Calendar;
    public class DisplayWeekNumber2 {
        public static void main(String[] args) {
            Calendar cal = Calendar.getInstance();
            System.out.println("Current week of month is : "
                    + cal.get(Calendar.WEEK_OF_MONTH));
            System.out.println("Current week of year is : "
                    + cal.get(Calendar.WEEK_OF_YEAR));
            cal.add(Calendar.WEEK_OF_MONTH, 1);
            System.out.println("date after one year : "
                    + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DATE)
                    + "-" + cal.get(Calendar.YEAR));
        }
    }
    
    Java

    上述代码示例将产生以下结果。

    Current week of month is : 4
    Current week of year is : 38
    date after one year : 9-24-2017
  • 相关阅读:
    sed匹配多行并替换其中的内容
    sysbench 安装、使用和测试
    linux inode号已满的解决办法
    Linux双网卡绑定
    es安装
    kibana安装
    filebeat
    Codeforces 464E The Classic Problem (最短路 + 主席树 + hash)
    Codeforces 1137C Museums Tour (强连通分量, DP)
    HDU 4921 Map(状态压缩)
  • 原文地址:https://www.cnblogs.com/borter/p/9613418.html
Copyright © 2011-2022 走看看