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.