Excel表格处理时间格式

2 篇文章 0 订阅

File sourceFile = new File(sourceUrl);

Sheet sourceSheet = WorkbookFactory.create(sourceFile).getSheetAt(0);

Row row= sourceSheet.getRow(1);

Cell createCell = row.getCell(2);

Cell lastCell = row.getCell(4);

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

DateFormat dateFormatNew = new SimpleDateFormat("hh:mm:ss");

String createTimeString = dateFormat.format(createCell.getDateCellValue());

String lastTimeString = dateFormat.format(lastCell.getDateCellValue());

LocalDateTime createTime = TimeUtils.parse(createTimeString);

LocalDateTime lastTime = TimeUtils.parse(lastTimeString);

System.out.println(createTime);

System.out.println(dateFormatNew.format(createCell.getDateCellValue()));

System.out.println(lastTime);

System.out.println(dateFormatNew.format(lastCell.getDateCellValue()));

Period period = Period.between(createTime.toLocalDate(),lastTime.toLocalDate());

System.out.println(period.getDays());

 

注释:source是excel表格路径  TimeUtils 是String转LocalDateTime的工具类,自己编写的。 可自己实现

createCell 是时间格式 如: 2018/8/1 4:12:55

lastCell 是时间格式 如: 2018/8/1 4:12:55

时间格式转换 只需关注上面带下划线的代码即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值