Java implementation adds several minutes to a certain time (HH: mm)

Source: Internet
Author: User
After using this function, I searched the internet and added only a few minutes to the current time, but not any time, so I wrote a sharing.
String starttime="08:30";int gap = 20;String newtime = addMin(starttime,gap);  

 

/*** The time (HH: Mm) provided by the root queue and the time interval between which a new time is returned ** arg1: initial time * arg2: ** return: returns the new time **/public static string addmin (string time, int gap) {try {string [] S = time. split (":"); int min = integer. parseint (s [1]) + gap % 60; int hour = integer. parseint (s [0]) + (GAP/60); If (min> = 60) {hour + = 1; Min-= 60;} If (hour> = 24) {hour = hour % 24;} return ("0" + hour ). substring ("0" + hour ). length ()-2, ("0" + hour ). length () ) + ":" + ("0" + min ). substring ("0" + min ). length ()-2, ("0" + min ). length ();} catch (exception e) {system. out. println ("addmin error! "+ E. tostring (); Return "";}}

 

// 100 results 08: 3008: 5009: 1009: 3009: 5010: 1010: 3010: 5011: 1011: 3011: 5012: 1012: 3012: 5013: 1013: 3013: 5014: 1014: 3014: 5015: 1015: 3015: 5016: 1016: 3016: 5017: 1017: 3017: 5018: 1018: 3018: 5019: 1019: 3019: 5020: 1020: 3020: 5021: 1021: 3021: 5022: 1022: 3022: 5023: 1023: 3023: 5000: 1000: 3000: 5001: 1001: 3001: 5002: 1002: 3002: 5003: 1003: 3003: 5004: 1004: 3004: 5005: 1005: 3005: 5006: 1006: 3006: 5007: 1007: 3007: 5008: 1008: 3008: 5009: 1009: 3009: 5010: 1010: 3010: 5011: 1011: 3011: 5012: 1012: 3012: 5013: 1013: 3013: 5014: 1014: 3014: 5015: 1015: 3015: 5016: 1016: 3016: 5017: 1017: 30

 

Related Article

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.