Perl 中的紀元時間
您可以在 Perl 中使用 time() 函式獲取紀元時間,即從一個特定日期開始經過的秒數,在 Unix 中該日期為 1970 年 1 月 1 日。
示例
#!/usr/local/bin/perl $epoc = time(); print "Number of seconds since Jan 1, 1970 - $epoc\n";
輸出
執行上述程式碼時,將產生以下結果 -
Number of seconds since Jan 1, 1970 - 1361022130
您可以按照以下方法將給定的秒數轉換為日期和時間字串 -
示例
#!/usr/local/bin/perl $datestring = localtime(); print "Current date and time $datestring\n"; $epoc = time(); $epoc = $epoc - 24 * 60 * 60; # one day before of current date. $datestring = localtime($epoc); print "Yesterday's date and time $datestring\n";
輸出
執行上述程式碼時,將產生以下結果 -
Current date and time Tue Jun 5 05:54:43 2018 Yesterday's date and time Mon Jun 4 05:54:43 2018
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP