# C # Seconds To date _ number of seconds to get a date days hours _ current datetime, converted to seconds

Source: Internet
Author: User

`///<summary>///by the number of seconds to get the date a few days a few hours ... ///</summary///<param name= "T" >Number of seconds</param>///<param name= "type" >0: Converted with seconds, 1: No seconds after conversion</param>///<returns>a few days, hours, minutes, seconds .</returns> Public Static stringParsetimeseconds (intTinttype) {stringR ="";intDay , hour, minute, second;if(T >=86400)//days,{ Day= Convert.ToInt16 (t/86400); hour= Convert.ToInt16 ((t%86400) /3600); minute= Convert.ToInt16 ((t%86400%3600) / -); second= convert.toint16 (t%86400%3600% -);if(Type = =0) R= Day + (" Day") + Hour + ("Hour") + Minute + ("minute") + Second + ("Second");ElseR= Day + (" Day") + Hour + ("Hour") + Minute + ("minute");}Else if(T >=3600)//when the{Hour= Convert.ToInt16 (t/3600); minute= Convert.ToInt16 ((t%3600) / -); second= convert.toint16 (t%3600% -);if(Type = =0) R= Hour + ("Hour") + Minute + ("minute") + Second + ("Second");ElseR= Hour + ("Hour") + Minute + ("minute");}Else if(T >= -)//points{minute= Convert.ToInt16 (t/ -); second= convert.toint16 (t% -); R= Minute + ("minute") + Second + ("Second");}Else{Second=convert.toint16 (t); R= Second + ("Second");}returnR;}/// <summary>///Current date time, converted to seconds/// </summary>/// <returns>Number of seconds</returns> Public Static stringxdateseconds () {LongXdateseconds =0;D atetime Xdatenow= Datetime.utcnow;//current UTC TimeLongXminute = -;//one minute, 60 seconds .LongXhour =3600;LongXday =86400;LongByear =1970;//seconds from 1970-1-1 0:00:00 to nowLong[] Xmonth = {0, to, -, -, -,151,181,212,243,273,304,334 };Long[] Xyear = {365,366 };Longnum =0; Xdateseconds+ = Xdatenow. Second;//count SecondsXdateseconds + = Xdatenow. Minute * Xminute;//Counting pointsXdateseconds + = Xdatenow. Hour * Xhour;//Counting TimeXdateseconds + = (xdatenow. Day-1) * Xday;//count the days//Calculate month (month to day count)if(Datetime.isleapyear (Xdatenow. Year) {Xdateseconds+ = (Xmonth[xdatenow. Month-1] +1) *Xday;}Else{xdateseconds+ = (Xmonth[xdatenow. Month-1]) *Xday;}//calculate year (year to day calculation)LongLyear = Xdatenow. Year-byear; for(inti =0; i < lyear; i++){if(Datetime.isleapyear (int) Byear +i)) {num++;}} Xdateseconds+ = ((lyear-num) * xyear[0] + num * xyear[1]) *Xday;returnXdateseconds. ToString ();}/// <summary>///number of seconds turn date/// </summary>/// <param name= "Value" >Number of seconds</param>/// <returns>Date</returns> Public StaticDateTime Getgmtdatetime (intValue) {//number of seconds turn time date//GMT time starts from January 1, 2000, first as the initial valueLongYear = -, Month =1, day =1;LongHour =0, Min =0, Sec =0;//Temp VariableLongIyear =0, Iday =0;LongIhour =0, Imin =0, ISec =0;//calculate the year that the file was createdIyear = Value/(365* -* -* -); year= year +iyear;//calculate how many days the file will be created except for the whole yearIday = (Value% (365* -* -* -)) / ( -* -* -);//calculates the number of years in a leap yearintRInt =0; for(inti = -; i < year; i++){if((i%4) ==0) RInt= RInt +1;}//calculate when the file was created (when)Ihour = ((Value% (365* -* -* -)) % ( -* -* -)) / ( -* -); Hour= Hour +Ihour;//Calculate file creation time (in minutes)Imin = (((Value% (365* -* -* -)) % ( -* -* -)) % ( -* -)) / -; Min= Min +Imin;//calculate the time the file was created (in seconds)ISec = (((Value% (365* -* -* -)) % ( -* -* -)) % ( -* -)) % -; Sec= Sec +Isec;datetime T=NewDateTime (int) year, (int) Month, (int) Day, (int) Hour, (int) Min, (int) Sec);D atetime T1= T.adddays (Iday-RInt);returnT1;} Gross position seconds to datatime format, note time zone, default is GMT Gmtdatetime DT=NewDateTime (1970,1,1,0,0,0,0). ToLocalTime (). AddSeconds (info.ltime); Uploadtime. Text=string. Format ("{0:f}", DT);`

C # Seconds To date _ number of seconds to get a date days hours _ current datetime, converted to seconds

Related Keywords:

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.