ASP provides a function called DateDiff(). This function can return a time difference in seconds. That is to say, if we put in a Greenwich Mean Time and compare it with the current time, it will return seconds.
What I will introduce today is how to convert time (for example: 2008-8-8 13:45:22) into seconds in ASP, and the opposite function to convert seconds into time. Of course when time changes. There must be a relatively fixed time, which is Greenwich Mean Time. Think about it, because Greenwich Mean Time starts at "00:00:00 on January 1, 1970". ASP provides a function called DateDiff(). This function can return a time difference in seconds, which means that we Put in a Greenwich Mean Time and compare it with the current time and it will return seconds. But we also need to pay attention to the time zone. Our China is GMT+08:00:00 (that is, our China is in the eighth zone of the Greenwich Mean Time Zone). When returning seconds, we use ASP's DateAdd() function in Greenwich. Just add the read seconds to the time and return. Please see the specific code function below. The following is the ASP time conversion function code:
Copy the code code as follows:
<%
Function TimeToSecond(Str)
'Convert time to seconds function
Str = DateDiff("s","1970-01-01 08:00:00",Str)
TimeToSecond = Str
End Function
Function SecondToTime(Str)
'Convert seconds to time function
Str = DateAdd("s",Str,"1970-01-01 08:00:00")
SecondToTime = Str
End Function
'Simple usage example
response.write "Convert time to seconds:"&TimeToSecond(Now())&"<br>" response.write "Convert seconds to time:"&SecondToTime("1164074979")
%>
Ok, with the above time conversion function, we can complete such a search function. For example: Find the latest articles published within a few hours or days.