java getyearmonth_Java YearMonth getYear()用法及代码示例

Java中的YearMonth类的getYear()方法用于从与其一起使用的Yearyearth实例中获取Year字段的值。它以从MIN_YEAR到MAX_YEAR的整数形式返回Year字段的值。

用法:

public int getYear()

参数:此方法不接受任何参数。

返回值:它将年份字段的值作为整数从MIN_YEAR返回到MAX_YEAR。

以下程序说明了Java中YearMonth的getYear()方法:

示例1::

// Program to illustrate the getYear() method

import java.util.*;

import java.time.*;

import java.time.format.DateTimeFormatter;

public class GfG {

public static void main(String[] args)

{

// Create a YearMonth object

YearMonth thisYearMonth = YearMonth.of(2017, 8);

// Get the year field

System.out.println(thisYearMonth.getYear());

}

}

输出:

2017

示例2::

// Program to illustrate the getYear() method

import java.util.*;

import java.time.*;

import java.time.format.DateTimeFormatter;

public class GfG {

public static void main(String[] args)

{

// Create a YearMonth object

YearMonth thisYearMonth = YearMonth.of(2018, 5);

// Get the year field

System.out.println(thisYearMonth.getYear());

}

}

输出:

2018

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
帮忙优化以下代码:public void runTask(ReportResultTask data, RunListener runListener) { UseMasterDataTypeEnum dataTypeEnum = ReportCommonLogicHelper.judgeTaskParam(data); // params.put(ReportCommonMasterDataRelationHelper.ParamTypeEnum.USE_MASTER_ENUM, dataTypeEnum.getValue()); params.put(ReportCommonMasterDataRelationHelper.ParamTypeEnum.YEAR_MONTH, data.getYearAndMonth()); try { List<ReportResultInventoryConsumablesNonFirst> saveList = Collections.synchronizedList(new ArrayList<>()); ReportNonFirstInvBO bo = new ReportNonFirstInvBO(); bo.setParams(params); bo.setYearMonth(Func.toLong(data.getYearAndMonth())); LiteflowResponse response = flowExecutor.execute2Resp("flow-calc-non-first-data", bo, ReportNonFirstInvBO.class); if (response.isSuccess()) { saveList = bo.getResults(); } if (saveList != null & saveList.size() > 0) { saveList.stream().forEachOrdered(fun -> { bo.setDistributorCode(fun.getNonFirstDistributorCode()); bo.setYearMonth(fun.getYearMonth()); bo.setIdo(BigDecimal.ZERO); fun.getNonFirstData().stream().forEach(fun1 -> { bo.setProductLine(fun1.getProductLine()); LiteflowResponse idoResponse = flowExecutor.execute2Resp("flow-calc-non-first-calcIdo", bo, ReportNonFirstInvBO.class); if (idoResponse.isSuccess()) { if (fun1.getProductLine().equals(IDO_TOTAL_PL)) { fun1.getItemData().stream().filter(fun2 -> ResultConstance.IDO_TOTAL.equals(fun2.getItemName())).forEach(x -> x.setItemValue(bo.getIdo())); } else { fun1.getItemData().stream().filter(fun2 -> ResultConstance.IDO.equals(fun2.getItemName())).forEach(x -> x.setItemValue(bo.getIdo())); } } }); }); this.updateSystemFieldInfo(saveList, data); inventoryConsumablesNonFirstService.insertBatch(saveList); runListener.complete(); } else { runListener.error(String.format("所选【%s-%s】产品/经销商主数据为空", data.getYearAndMonth(), "")); } } catch (Exception e) { log.error(StringUtil.format("非一级试剂耗材库存报表处理出错【{}】", e.getMessage()), e); runListener.error(StringUtil.format("非一级试剂耗材库存报表处理出错【{}】", e.getMessage())); } }
06-08

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值