Calculation of time in Java

Source: Internet
Author: User

1. Description: Add a time difference to the previous period:

code example:

Date psd = sysdate ();

String workTimeP1 = Mapp.get ("work_time_")! = null? Mapp.get ("Work_time_"). ToString (): "0";
int News=integer.parseint (workTimeP1) *60;
Date ped=dateutils.addseconds (psd,news);

2. Calculation code for the time difference: take milliseconds as an example

public static int Secondsbetween (Date smdate,date bdate) throws Exception {
SimpleDateFormat sdf=new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); Time format
Smdate=sdf.parse (Sdf.format (smdate));
Bdate=sdf.parse (Sdf.format (bdate));
Calendar cal = Calendar.getinstance ();
Cal.settime (smdate);
Long time1 = Cal.gettimeinmillis ();
Cal.settime (bdate);
Long time2 = Cal.gettimeinmillis ();
Long between_seconds= (time2-time1)/(1000);

Return Integer.parseint (string.valueof (between_seconds));
}

Tbpbc35 c35=c35list.get (0);
C35.setlotstarttime (c36mindate);//lot start time is the earliest start time of the schedule
C35.setlotendtime (c36maxdate);//lot end time is the latest end of the schedule
int Seconds=this.secondsbetween (C35.getlotstarttime (), C35.getlotendtime ());
int mintues=seconds/60;
BigDecimal mb=new BigDecimal (mintues);
C35.setworktotaltime (MB);

3. Addition of Time:

int ps = C36.getprodstartdate (). getseconds ();//Current Time of Huawei sec
int news = ps-betweendate;//Current time plus
Date s = c36.getprodstartdate ();//Current time
S.setseconds (news);
C36.setprodstartdate (s);


This article is from the "Ancient Yan" blog, please be sure to keep this source http://610201092.blog.51cto.com/7852003/1653629

Calculation of time in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.