当前位置:网站首页>Enter the date format string as the production date of the commodity, and enter the shelf life (days); Calculate the number of days until today before the expiration date of the product. 1. Change the
Enter the date format string as the production date of the commodity, and enter the shelf life (days); Calculate the number of days until today before the expiration date of the product. 1. Change the
2022-06-30 04:30:00 【A fat man】
package demo;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
/**
* @author : htf
Enter the date format string as the production date of the product , Enter the shelf life ( God ); Calculation section Until today , How many days will the product expire
1、 The console input string is converted to date format
2、 Add the input date to the shelf life days
3、 Get the current system date , Compare two dates , If the output is expired “ This item has expired ”
*/
public class Test1 {
public static void main(String[] args) throws ParseException {
System.out.println(" Please enter the production date (yyyy-MM-dd)");
Scanner sc=new Scanner(System.in);
String d=sc.next();// Keyboard access time 2022-01-10
System.out.println(" Please enter the shelf life ( God )");
int day=sc.nextInt();// Acquisition time
SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyy-MM-dd");// Transformation format
Date date =sDateFormat.parse(d);// The time character obtained by the keyboard is converted into time
Calendar c =Calendar.getInstance();
c.setTime(date);// Setup time
c.add(Calendar.DATE, day);// Set the shelf life time
String str = sDateFormat.format(c.getTime());// Conversion time
System.out.println(" Today's date is :"+sDateFormat.format(new Date()));// current time
// Compare the number of milliseconds of the current date with the number of milliseconds after the number of days you want to add , If it is less than the number of days you want to add , The product has expired
if(c.getTimeInMillis()<new Date().getTime()) {
System.out.println(" It's overdue ");
}else {
// You want to add the millisecond value of the following days minus the millisecond value of the current time
long g=c.getTimeInMillis()-new Date().getTime();
long t=g/(3600*24*1000);// Format days
System.out.println(" There are also commodities "+t+" Days overdue ");
}
}
}
边栏推荐
- Configure specific source IP in SLA detection of FortiGate sdwan
- How the FortiGate firewall rejects a port by using the local in policy policy
- Qt 6.3.1Conan软件包发布
- 7-3 打怪升级 单源最短路
- JS deconstruction assignment
- win10系统使用浏览器下载后,内容无故移动或删除
- OneNote production schedule
- Use of thread pool
- Robot slam navigation core technology and practice Season 1: Chapter 0_ Slam development overview
- JS import and export
猜你喜欢

基于SSM框架茶叶商城系统【项目源码+数据库脚本+报告】

Es2017 key summary

Sql语句遇到的错误,求解

Technology sharing | broadcast function design in integrated dispatching

FortiGate firewall and Aruze cloud tunnel interruption

File system and directory operations

Threejs realizes the simulation of river, surface flow, pipe flow and sea surface

OneNote production schedule

Matlab reads fig file and restores signal

What is an optocoupler circuit and what should be paid attention to in actual use?
随机推荐
How the FortiGate firewall rejects a port by using the local in policy policy
Summary of the reasons why transactional doesn't work
FortiGate creates multiple corresponding DDNS dynamic domain names for multiple ADSL interfaces
破局存量客群营销,试一下客户分群管理(含聚类模型等实操效果评估)
Everyone, Flink 1.13.6, mysql-cdc2.2.0, the datetime (6) class extracted
JS reflect
7-3 single source shortest circuit for strange play upgrade
Qt Creator 8 Beta2发布
With the deep integration of cloud platform, the "Xueba" objectscale in the object storage industry is coming
深度融合云平台,对象存储界的“学霸”ObjectScale来了
FortiGate firewall modifies the default timeout of a session
Myrpc version 3
Salary management system based on servlet+jsp+mysql [source code + database]
输入输出及中断技术——微机第六章学习笔记
Robot slam navigation core technology and practice Season 1: Chapter 0_ Slam development overview
Junior students summarize JS advanced interview questions
数据链路层详解
Sql语句遇到的错误,求解
Threejs realizes the simulation of river, surface flow, pipe flow and sea surface
Myrpc version 0