您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 销售管理 > C时间戳转换为普通时间
C#时间戳转换为普通时间//时间戳转为C#格式时间privateDateTimeStampToDateTime(stringtimeStamp){DateTimedateTimeStart=TimeZone.CurrentTimeZone.ToLocalTime(newDateTime(1970,1,1));longlTime=long.Parse(timeStamp+0000000);TimeSpantoNow=newTimeSpan(lTime);returndateTimeStart.Add(toNow);}//DateTime时间格式转换为Unix时间戳格式privateintDateTimeToStamp(System.DateTimetime){System.DateTimestartTime=TimeZone.CurrentTimeZone.ToLocalTime(newSystem.DateTime(1970,1,1));return(int)(time-startTime).TotalSeconds;}//获取日期+时间DateTime.Now.ToString();//2008-9-420:02:10DateTime.Now.ToLocalTime().ToString();//2008-9-420:12:12//获取日期DateTime.Now.ToLongDateString().ToString();//2008年9月4日DateTime.Now.ToShortDateString().ToString();//2008-9-4DateTime.Now.ToString(yyyy-MM-dd);//2008-09-04DateTime.Now.Date.ToString();//2008-9-40:00:00//获取时间DateTime.Now.ToLongTimeString().ToString();//20:16:16DateTime.Now.ToShortTimeString().ToString();//20:16DateTime.Now.ToString(hh:mm:ss);//08:05:57DateTime.Now.TimeOfDay.ToString();//20:33:50.7187500//其他DateTime.ToFileTime().ToString();//128650040212500000DateTime.Now.ToFileTimeUtc().ToString();//128650040772968750DateTime.Now.ToOADate().ToString();//39695.8461709606DateTime.Now.ToUniversalTime().ToString();//2008-9-412:19:14DateTime.Now.Year.ToString();获取年份//2008DateTime.Now.Month.ToString();获取月份//9DateTime.Now.DayOfWeek.ToString();获取星期//ThursdayDateTime.Now.DayOfYear.ToString();获取第几天//248DateTime.Now.Hour.ToString();获取小时//20DateTime.Now.Minute.ToString();获取分钟//31DateTime.Now.Second.ToString();获取秒数//45//n为一个数,可以数整数,也可以事小数dt.AddYears(n).ToString();//时间加n年dt.AddDays(n).ToString();//加n天dt.AddHours(n).ToString();//加n小时dt.AddMonths(n).ToString();//加n个月dt.AddSeconds(n).ToString();//加n秒dt.AddMinutes(n).ToString();//加n分
本文标题:C时间戳转换为普通时间
链接地址:https://www.777doc.com/doc-2908561 .html