ASP transform GMT function DateDiff () application Technology

Source: Internet
Author: User
What I'm going to introduce today is a function that converts time (for example: 2008-8-8 13:45:22) into seconds in ASP, and the opposite of converting seconds to time. Of course when the time is converted. Must have a relatively fixed time, that is GMT. Think about it. Because Greenwich Mean Time is "January 1, 1970 00:00:00" Start, ASP provides a function called DateDiff (), this function can return a time difference of seconds, That means we put in a Greenwich mean time compared to the current time, return to the second OK. But we also need to pay attention to time zone, we China is gmt+08:00:00 (that is to say we are in the Greenwich Standard Time zone eighth), the second return to use the ASP's DATEADD () function in Greenwich time plus read out seconds after the line. See below for specific code functions The following is the ASP time conversion function code:
Copy Code code as follows:

<%
Function Timetosecond (STR)
' Time to seconds ' function
str = DateDiff ("s", "1970-01-01 08:00:00", str)
Timetosecond = Str
End Function

Function Secondtotime (STR)
' Seconds to time function
str = DATEADD ("s", str, "1970-01-01 08:00:00")
Secondtotime = Str
End Function

' Simple examples of use
Response.Write Time to seconds: &timetosecond (now) & <br> Response.Write seconds Convert to time: &secondtotime 1164074979 ")
%>

Ok, with the above time conversion function, we can complete the search function. For example: Find the latest articles published in hours or days.
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.