日历类set()方法 (Calendar Class set() method)

Syntax:

句法:

    public void set(int fi, int val);
public final void set(int yy, int mm, int dd);
public final void set(int yy, int mm, int dd, int hours, int min);
public final void set(int yy, int mm, int dd, int hours, int min, int sec);

  • set() method is available in java.util package.

    set()方法在java.util包中可用。

  • set(int fi, int val) method is used to sets the specified calendar field(fi) with the specified value(val).

    set(int fi,int val)方法用于将指定的日历字段(fi)设置为指定的value(val)。

  • set(int yy, int mm, int dd) method is used to puts the values for the given calendar fields month(mm), year(yy) & date(dd).

    set(int yy,int mm,int dd)方法用于放置给定日历字段month(mm),year(yy)和date(dd)的值。

  • set(int yy, int mm, int dd, int hours, int min) method is used to puts the values for the given calendar fields year(yy), month(mm), date(dd), hours in a day(hours), & minutes(min).

    set(int yy,int mm,int dd,int hours,int min)方法用于放置给定日历字段的值year(yy),month(mm),date(dd),一天中的小时数(小时) )和分钟(分钟)。

  • set(int yy, int mm, int dd, int hours, int min, int sec) method is used to puts the value for the given calendar fields year(yy), month(mm), date(dd), hours in a day(hours), minutes(min), seconds(sec).

    set(int yy,int mm,int dd,int hours,int min,int sec)方法用于将给定日历字段的值year(yy),month(mm),date(dd),hours放入天(小时),分钟(分钟),秒(秒)。

  • These methods don't throw an exception at the time of setting the values of the specified fields.

    在设置指定字段的值时,这些方法不会引发异常。

  • These are non-static methods, so it is accessible with the class object and if we try to access these methods with the class name then we will get an error.

    这些是非静态方法,因此可以通过类对象进行访问,如果尝试使用类名称访问这些方法,则会收到错误消息。

Parameter(s):

参数:

  • In the first case set(int fi, int val),

    在第一种情况下(int fi,int val)

    • int fi – represents the calendar field need to be changed.
    • int fi –表示需要更改日历字段。
    • int val – represents the value for the given calendar field(fi).
    • int val –表示给定日历字段(fi)的值。
  • In the second case, set(int yy, int mm, int dd),

    在第二种情况下, set(int yy,int mm,int dd)

    • int yy – represents the value for the calendar field year(yy).
    • int yy –表示日历字段year(yy)的值。
    • int mm – represents the value for the calendar field month(mm).
    • int mm –表示日历字段month(mm)的值。
    • int dd – represents the value for the calendar field date(dd).
    • int dd –表示日历字段date(dd)的值。
  • In the third case, set(int yy, int mm, int dd, int hours, int min),

    在第三种情况下, 设置(int yy,int mm,int dd,int hours,int min)

    • int yy – represents the value for the calendar field year(yy).
    • int yy –表示日历字段year(yy)的值。
    • int mm – represents the value for the calendar field month(mm).
    • int mm –表示日历字段month(mm)的值。
    • int dd – represents the value for the calendar field date(dd).
    • int dd –表示日历字段date(dd)的值。
    • int hours – represents the value for the calendar field hours(hours).
    • int hours –表示日历字段的小时数(小时)。
    • int min – represents the value for the calendar field minutes(min).
    • int min –表示日历字段的分钟数(min)的值。
  • In the fourth case, set(int yy, int mm, int dd, int hours, int min, int sec),

    在第四种情况下, 设置(int yy,int mm,int dd,int hours,int min,int sec)

    • int yy – represents the value for the calendar field year(yy).
    • int yy –表示日历字段year(yy)的值。
    • int mm – represents the value for the calendar field month(mm).
    • int mm –表示日历字段month(mm)的值。
    • int dd – represents the value for the calendar field date(dd).
    • int dd –表示日历字段date(dd)的值。
    • int hours – represents the value for the calendar field hours(hours).
    • int hours –表示日历字段的小时数(小时)。
    • int min – represents the value for the calendar field minutes(min).
    • int min –表示日历字段的分钟数(min)的值。
    • int sec – represents the value for the calendar field seconds(sec).
    • int sec –表示日历字段的秒(sec)的值。

Return value:

返回值:

In all the cases , the return type of the method is void, it returns nothing.

在所有情况下,该方法的返回类型都是void ,它什么也不返回。

Example:

例:

// Java Program to demonstrate the example of
// void set() method of Calendar
import java.util.*;
public class Set {public static void main(String args[]) {// Instantiating a Calendar object
Calendar ca = Calendar.getInstance();
// Display calendar
System.out.println("ca: " + ca.getTime());
// By using set(int fi, int val) is to set
// the month field to 6 of this calendar
ca.set(Calendar.MONTH, 6);
// Display calendar
System.out.println("ca.set(Calendar.MONTH, 6): " + ca.getTime());
// By using set(int yy, int mon,int date) is to set
// the year, month & date field of this calendar
ca.set(1998, 06, 12);
// Display calendar
System.out.println("ca.set(1998,06,12): " + ca.getTime());
// By using set(int yy, int mon,int date, int hour_of_day, int min)
// is to set the year, month , date , hours and minute
// field of this calendar
ca.set(1998, 06, 12, 06, 30);
// Display calendar
System.out.println("ca.set(1998,06,12,06,30): " + ca.getTime());
// By using set(int yy, int mon,int date, int hour_of_day, int min, int sec)
// is to set the year, month , date , hours and minute and seconds
// field of this calendar
ca.set(1998, 06, 12, 06, 30, 20);
// Display calendar
System.out.println("ca.set(1998,06,12,06,30,20): " + ca.getTime());
}
}

Output

输出量

ca: Sat Feb 01 21:14:13 GMT 2020
ca.set(Calendar.MONTH, 6): Wed Jul 01 21:14:13 GMT 2020
ca.set(1998,06,12): Sun Jul 12 21:14:13 GMT 1998
ca.set(1998,06,12,06,30): Sun Jul 12 06:30:13 GMT 1998
ca.set(1998,06,12,06,30,20): Sun Jul 12 06:30:20 GMT 1998

翻译自: https://www.includehelp.com/java/calendar-set-method-with-example.aspx

Java Calendar set()方法与示例相关推荐

  1. cdate在java中_Java Calendar.add方法代码示例

    本文整理汇总了Java中java.util.Calendar.add方法的典型用法代码示例.如果您正苦于以下问题:Java Calendar.add方法的具体用法?Java Calendar.add怎 ...

  2. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  3. java的calendar的get_Java Calendar get()方法与示例

    日历类get()方法get()方法在java.util包中可用. get()方法用于检索此Calendar的给定参数fi(field)的值. get()方法是一个非静态方法,可通过类对象访问,如果尝试 ...

  4. python中weekday_Python calendar.weekday方法代码示例

    本文整理汇总了Python中calendar.weekday方法的典型用法代码示例.如果您正苦于以下问题:Python calendar.weekday方法的具体用法?Python calendar. ...

  5. java calendar.add方法_Java Calendar add()方法与示例

    日历类add()方法add()方法在java.util包中可用. add()方法用于对指定的cal_fi(日历字段)执行相加或相减的时间量. add()方法是一个非静态方法,可通过类对象访问,如果尝试 ...

  6. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  7. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  8. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  9. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  10. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

最新文章

  1. WindowsServer2012史记7-茴香豆的五种写法和四种”显示计算机”的方法
  2. GT Transceiver中的重要时钟及其关系(5)QPLL的工作原理介绍
  3. OpenSSL 再爆严重安全漏洞 —— CCS 注入
  4. 电子政务“云”成大势
  5. Boost:bind绑定和或||的测试程序
  6. asp.net core webApi 参数保护
  7. iOS开发UIScrollView的底层实现
  8. 24.Forbidden
  9. sql基本语句返回值类型
  10. 视频解码测试软件,视频解码:视频解码性能测试_平板电脑评测-中关村在线
  11. Liunx安装teamview15以及出现ID密码为空如何解决
  12. keil编译出现多重定义的问题
  13. jquery 蔚蓝网
  14. 编程入门: 自学编程从哪里开始? [初学参考]
  15. 服务器文件系统报错处理办法
  16. C语言limits.h和float.h头文件
  17. VSCode Conventional Commits 插件
  18. 计算机底层架构(偏硬件)综述
  19. 基于SSM实现的医院医药药品管理系统-JAVA【数据库设计、源码、开题报告】
  20. macOS:M1 上安装 Rosetta 2

热门文章

  1. 哈尔滨工程大学计算机学院拟录取名单,哈尔滨工程大学公布拟录取名单,初试成绩相差150分,双双录取...
  2. 这份java突击核心面试宝典(原理+应用+源码+调优),闯进大厂
  3. 在windows部署hadoopSpark和IDEA
  4. 超市服务器的维护和管理制度,超市管理制度-20210711072121.docx-原创力文档
  5. 关于JVM调优的工具及JVM 常见调优参数
  6. java包无法打开变成压缩包的解决办法
  7. java for循环创建对象_for循环创建对象
  8. 固态存储设备固件升级方案
  9. 本周末CSDN博客暂时停止服务公告
  10. Hive读取复杂的数据类型(Array,Map,Struct)