java获取当年第一天

/**
* 当前月第一天
*
* @return 当前月第一天
*/
public String getThisMonth() {
// 获取前月的第一天
Calendar calendar = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat(“yyyy-MM-dd”);
calendar.add(Calendar.MONTH, 0);
calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
String firstDay = format.format(calendar.getTime());
return firstDay;
}

/**
 * 日期是本月的第几天
 * 
 * @param date
 *            天
 * @return 当前天数
 * @throws ParseException
 *             数据转换异常
 */
public static String getMostDay(String date) throws ParseException {
    // 当天日期是本月的第几天
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    Date nowDay = format.parse(date);
    Calendar ca = Calendar.getInstance();
    ca.setTime(nowDay);
    int num = ca.get(Calendar.DAY_OF_MONTH);
    String time = String.valueOf(num);
    return time;
}

/**
 * 获取日期在当月天数
 * 
 * @param date
 *            天
 * @return 当月天数
 * @throws Exception
 *             异常
 */
public static String getMonthDay(String date) throws Exception {
    // 当前月最大日期
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date dates = sdf.parse(date);// String-->Date
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(dates);// 设置日历时间
    int day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    String mostDate = String.valueOf(day);
    return mostDate;
}

/**
 * 当年第一天
 * 
 * @param date
 *            日期
 * @return 天
 * @throws Exception
 *             异常
 */
public static String getThisYear(String da
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值