java.util.Date.setMonth()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.4k)|赞(0)|评价(0)|浏览(321)

本文整理了Java中java.util.Date.setMonth()方法的一些代码示例,展示了Date.setMonth()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Date.setMonth()方法的具体详情如下:
包路径:java.util.Date
类名称:Date
方法名:setMonth

Date.setMonth介绍

[英]Sets the gregorian calendar month for this Date object.
[中]设置此日期对象的公历月份。

代码示例

代码示例来源:origin: stackoverflow.com

Date date = user.getBirthDate();
date.setMonth(1);  // mutated!

代码示例来源:origin: spotbugs/spotbugs

/**
   * @param args
   */
  @ExpectWarning("DMI,DLS")
  public static void main(String[] args) {

    Date x = new Date();
    x.setMonth(12);
    x.setMonth(-1);

    String month = "January";

    System.out.println(month.toUpperCase());
    month = month.toUpperCase();
  }
}

代码示例来源:origin: spotbugs/spotbugs

@ExpectWarning("DMI_BAD_MONTH")
void bug(Date date) {
  date.setMonth(12);
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Sets the currently specified date.
 *
 * @param currentDate the currently specified date
 */
public void setCurrentMonth(Date currentDate) {
 this.currentMonth.setYear(currentDate.getYear());
 this.currentMonth.setMonth(currentDate.getMonth());
}

代码示例来源:origin: com.google.gwt/gwt-servlet

@Override
public void setMonth(int month) {
 checkFrozen();
 super.setMonth(month);
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Adds the given number of months to a date.
 * 
 * @param date the date
 * @param months number of months
 */
@SuppressWarnings("deprecation") // GWT requires Date
public static void addMonthsToDate(Date date, int months) {
 if (months != 0) {
  int month = date.getMonth();
  int year = date.getYear();
  int resultMonthCount = year * 12 + month + months;
  int resultYear = (int) Math.floor(resultMonthCount / 12.0);
  int resultMonth = resultMonthCount - resultYear * 12;
  date.setMonth(resultMonth);
  date.setYear(resultYear);
 }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Constructor.
 */
public CalendarModel() {
 currentMonth = new Date();
 CalendarUtil.setToFirstDayOfMonth(currentMonth);
 // Finding day of week names
 Date date = new Date();
 for (int i = 1; i <= DAYS_IN_WEEK; i++) {
  date.setDate(i);
  int dayOfWeek = date.getDay();
  dayOfWeekNames[dayOfWeek] = getDayOfWeekFormatter().format(date);
 }
 // Finding day of month names
 date.setMonth(0);
 for (int i = 1; i < MAX_DAYS_IN_MONTH; ++i) {
  date.setDate(i);
  dayOfMonthNames[i] = getDayOfMonthFormatter().format(date);
 }
 // finding month names
 date.setDate(1);
 for (int i = 0; i < MONTHS_IN_YEAR; ++i) {
  date.setMonth(i);
  monthOfYearNames[i] = getMonthFormatter().format(date);
 }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

date.setMonth(this.month);

代码示例来源:origin: stackoverflow.com

public static  void main(String[] args) {
 for(int i=0;i<10; i++) {
  Date date = new Date();
  Date updated = (Date)date.clone();
  addMonths(updated, i);
  System.out.println(" original: " + date+  " adding " +i+ " months: " + updated);
 }
}

public static void addMonths(Date date, int numMonths){
 date.setMonth((date.getMonth() - 1 + numMonths) % 12 + 1);
}

代码示例来源:origin: stackoverflow.com

SimpleDateFormat formatter=new SimpleDateFormat("ddMMMyyyy HH:mm");
 Date today = new Date();
 today.setMonth(8);
 String result = formatter.format(today);
 System.out.println(result);

代码示例来源:origin: mulesoft/mule

@Test
public void fromDate() {
 Date date = new Date();
 date.setYear(0);
 date.setMonth(0);
 date.setDate(1);
 assertEquals(1900, new DateTime(date).getYear());
 assertEquals(1, new DateTime(date).getMonth());
 assertEquals(1, new DateTime(date).getDayOfMonth());
}

代码示例来源:origin: mulesoft/mule

@Test
public void fromDate() {
 Date date = new Date();
 date.setYear(0);
 date.setMonth(0);
 date.setDate(1);
 assertEquals(1900, new DateTime(date).getYear());
 assertEquals(1, new DateTime(date).getMonth());
 assertEquals(1, new DateTime(date).getDayOfMonth());
}

代码示例来源:origin: mulesoft/mule

@Test
public void fromDate() {
 Date date = new Date();
 date.setYear(0);
 date.setMonth(0);
 date.setDate(1);
 assertEquals(1900, new DateTime(date).getYear());
 assertEquals(1, new DateTime(date).getMonth());
 assertEquals(1, new DateTime(date).getDayOfMonth());
}

代码示例来源:origin: com.google.web.bindery/requestfactory-server

@Override
public void setMonth(int month) {
 checkFrozen();
 super.setMonth(month);
}

代码示例来源:origin: net.wetheinter/gwt-user

/**
 * Sets the currently specified date.
 *
 * @param currentDate the currently specified date
 */
public void setCurrentMonth(Date currentDate) {
 this.currentMonth.setYear(currentDate.getYear());
 this.currentMonth.setMonth(currentDate.getMonth());
}

代码示例来源:origin: stackoverflow.com

public static String getMonthName(int month){
  Locale locale = Locale.getDefault();
  SimpleDateFormat sdf = new SimpleDateFormat("MMMM",locale);
  Date date = new Date();
  date.setDate(1);
  date.setMonth(month);
  date.setYear(2012);
  return sdf.format(date);
}

代码示例来源:origin: stackoverflow.com

Date date = new Date();
date.setYear(2010);
date.setMonth(07);
date.setDate(14)
date.setHours(9);
date.setMinutes(0);
date.setSeconds(0);
String time = new SimpleDateFormat("HH:mm:ss").format(date);

代码示例来源:origin: org.kie.soup/kie-soup-dataset-api

@Before
public void setUp() throws Exception {
  Date startTime = new Date();
  startTime.setYear(115);
  startTime.setMonth(10);
  startTime.setDate(10);
  startTime.setHours(12);
  startTime.setMinutes(50);
  startTime.setSeconds(30);
  TimeInstant.START_TIME = startTime;
}

代码示例来源:origin: org.dashbuilder/dashbuilder-dataset-api

@Before
public void setUp() throws Exception {
  Date startTime = new Date();
  startTime.setYear(115);
  startTime.setMonth(10);
  startTime.setDate(10);
  startTime.setHours(12);
  startTime.setMinutes(50);
  startTime.setSeconds(30);
  TimeInstant.START_TIME = startTime;
}

代码示例来源:origin: org.mule.runtime/mule-core-tests

@Test
public void fromDate() {
 Date date = new Date();
 date.setYear(0);
 date.setMonth(0);
 date.setDate(1);
 assertEquals(1900, new DateTime(date).getYear());
 assertEquals(1, new DateTime(date).getMonth());
 assertEquals(1, new DateTime(date).getDayOfMonth());
}

相关文章