Time stamp to time format, time format to time stamp, time format conversion
-- Convert a timestamp to a time type in SQL
SQL contains a DATEADD function. The timestamp is the number of seconds between 08:00:00 and the time. So you only need to add the timestamp 08:00:00 to get the desired time. select DATEADD (second, 1488272688 + 8*60*60, '2017-01-01 00:00:00 ')
Note: Relationship between Beijing time and GMT time
1. GMT is the Central Time Zone. Beijing is located in the east 8 zone, with a difference of 8 hours.
2. Therefore, Beijing time = GMT + 8 hours
E.g:
SELECT DATEADD (S, 1488272688 + 8 * 3600, '1970-01-01 00:00:00')-Timestamp converted to ordinary time
SELECT DATEDIFF (S, '1970-01-01 00:00:00', '2017-02-28 17: 04: 48.000')-8 * 3600-ordinary time is converted into timestamp
-- Convert the timestamp into a time type in the background code
public DateTime ConvertDate(long span)
{
DateTime time = DateTime.MinValue;
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0, 0));
time = startTime.AddSeconds(span);
return time;
}
Well, there are two types of conversions between the database and the background.