Atitit. Best Practice for converting Standard Time formats to seconds, atitit Best Practice

Source: Internet
Author: User

Atitit. Best Practice for converting Standard Time formats to seconds, atitit Best Practice

Atitit. Best Practice for converting Standard Time formats into seconds

 

For example, 00:01:19 is converted to 79 seconds, and is converted to each other.

 

One idea is to use div 60 mod... but it is troublesome...

 

A better way is to use stamp

...

 

Add a date to the foreground and use the timestamp for calculation...

 

Author: old wow's paw Attilax iron, EMAIL: 1466519819@qq.com

Reprinted please indicate Source: http://blog.csdn.net/attilax

 

 

Public static void main (String [] args) throws ParseException {

// TODO Auto-generated method stub

String s = "00:01:09 ";

Int sec = str2secs (s); // 69

System. out. println (sec );

Sec = 79; // 00:01:19

System. out. println (secs2str (sec ));

}

 

Private static String secs2str (int sec) throws ParseException {

String date = "2014-01-01 ";

Date start = DateUtil. str2date_excpt (date + "00:00:00", true );

Long endTimestamp = sec * 1000 + start. getTime ();

Date end = new Date (endTimestamp );

String s = DateUtil. date2str (end, true );

String [] sa = s. split ("");

Return sa [1];

}

 

Private static int str2secs (String s) throws ParseException {

String date = "2014-01-01 ";

String full = date + "" + s;

Date dt = DateUtil. str2date_excpt (full, true );

Date dt2 = DateUtil. str2date_excpt (date + "00:00:00", true );

Int I = DateUtil. getSecondInterval (dt2, dt );

 

Return I;

}

 

Reference

Paip. Date and Time operations and timestamp uapi php java python Summary-attilax column-blog channel-CSDN.NET.htm


How to convert the number of milliseconds to the standard timestamp in. net?

TimeSpan ts = new TimeSpan (1251790200000*10 );
Ts. Days indicates the number of Days.
Ts. Hours indicates the corresponding Hours,
Push classes in sequence.
Note:
// Parameters:
// Ticks:
// A time period expressed in 100-nanosecond units.
Public TimeSpan (long ticks );

You can also Add a variable of the DateTime type to get the time after addition and subtraction.

Converts Greenwich Mean Time to a common time format and inserts it into the database in the standard time format.

Is Greenwich Mean Time and time format a concept? How can they be converted? I also want to know.
 

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.