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.