Today, we need to import a news system data based on MS SQL database into Phpcms v9, the source system news date format is "2014-01-15 10:45:49",
And Phpcms is used in the integer timestamp, in PHP is very simple, with strtotime () can be;
In C #, you need to write your own functions, in the following steps:
Step 1: Calculate the base time for the timestamp in the PHPCMS first.
1 TimeSpan ts = new TimeSpan (0,0,0,1389753949); 2 DateTime now = Convert.todatetime ("2014-01-15 10:45:49"); 3 DateTime basetime = now-ts;4 Response.Write (Basetime.tostring ()); 5 Response.Write ("<br/>");
displayed on the page was 1970-1-1 8:00:00, the base time was obtained
Step 2: The conversion time is an integer timestamp.
1 //benchmark for "1970-1-1 8:00:00" time to integer 2 basetime = Convert.todatetime ("1970-1-1 8:00:00"); 3 ts = DateTime.Now- Basetime;4 Long intervel = (long) ts. Totalseconds;5 Response.Write ("Current time converted to:" + intervel. ToString ());
The resulting integer is from 1970-1-1 8:00:00 to the current number of seconds, namely Phpcms v9 in V9_news table inputtime column, updatetime column value source
Appendix: Date Conversion to timestamp
PHP provides functions that can easily convert various forms of a date to a timestamp, which is mainly:
- Strtotime (): Resolves the datetime description of any English text to a timestamp.
- Mktime (): Gets the timestamp from the date.
Strtotime ()
The Strtotime () function is used to convert the date represented by the English text string to a timestamp, an inverse of date (), which returns the timestamp successfully, otherwise FALSE.
Grammar:
int Strtotime (string time [, int now])
The parameter time is the parsed string and is the date represented by the GNU date input format.
Example:
<?phpecho strtotime ("2009-10-21 16:00:10");//Output 1256112010echo Strtotime ("September 2008");//Output 1220976000echo Strtotime ("+1 Day"), "<br/>";//Output the timestamp of tomorrow at this time?>
C # time-to-integer (timestamp), mimicking some functions of PHP strtotime functions