如何获得一个月第一天的名字? [英] How to get name of the first day of a month?

查看:113
本文介绍了如何获得一个月第一天的名字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得本月的第一天?因此,对于今年1月份,它将在周日返回。然后在二月它会在周三返回。

How would I go about getting the first day of the month? So for January, of this year, it would return Sunday. And then for February it would return Wednesday.

推荐答案

要获得当月的第一个日期,请使用 java.util.Calendar中。首先获取它的实例并将字段 Calendar.DAY_OF_MONTH 设置为该月的第一个日期。由于任何月份的第一天为1,取代 cal.getActualMinimum(Calendar.DAY_OF_MONTH),此处可以使用1。

To get the first date of the current month, use java.util.Calendar. First get an instance of it and set the field Calendar.DAY_OF_MONTH to the first date of the month. Since the first day of any month is 1, inplace of cal.getActualMinimum(Calendar.DAY_OF_MONTH), 1 can be used here.

private Date getFirstDateOfCurrentMonth() {
  Calendar cal = Calendar.getInstance();
  cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
  return cal.getTime();
}

这篇关于如何获得一个月第一天的名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆