Time stamp to time format, time format to time stamp, time format conversion

Source: Internet
Author: User
Tags central time zone

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.

 


Related Article

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.