Formatting time
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
Method 1:
Use posix qw (strftime); my $ timestr1 = strftime "% Y-% m-% d", localtime; my $ timestr2 = strftime "% Y-% m-% d", localtime (time-86400); (previous day) print "$ timestr \ n ";
Method 2:
#! /Usr/bin/perl ($ sec, $ min, $ hour, $ day, $ Mon, $ year, $ weekday, $ yeardate, $ savinglightday) = (localtime (time); $ sec = ($ sec <10 )? "0 $ sec": $ sec; $ min = ($ min <10 )? "0 $ min": $ min; $ hour = ($ hour <10 )? "0 $ Hour": $ hour; $ day = ($ day <10 )? "0 $ Day": $ day; $ MON = ($ mon <9 )? "0 ". ($ mon + 1) :( $ mon + 1); $ year + = 1900; $ today = "$ day. $ mon. $ year | $ hour: $ min: $ sec "; print $ today. "\ n"; print time. "\ n"; # If you want to output the date before the day, subtract time from the number of seconds (86400) of the day ). (Localtime (time-86400 ));#! /Usr/bin/perlprint & get_time (10 ). "\ n"; sub get_time {$ interval = $ _ [0] * 60; ($ sec, $ min, $ hour, $ day, $ Mon, $ year, $ weekday, $ yeardate, $ savinglightday) = (localtime (Time + $ interval); $ sec = ($ sec <10 )? "0 $ sec": $ sec; $ min = ($ min <10 )? "0 $ min": $ min; $ hour = ($ hour <10 )? "0 $ Hour": $ hour; $ day = ($ day <10 )? "0 $ Day": $ day; $ MON = ($ mon <9 )? "0 ". ($ mon + 1) :( $ mon + 1); $ year + = 1900; Return "$ year-$ mon-$ day $ hour: $ min: $ sec.00 ";} sub gettime () {(my $ sec, my $ min, my $ hour, my $ day, my $ Mon, my $ year, my $ weekday, my $ yeardate, my $ savinglightday) = (localtime (time); $ sec = ($ sec <10 )? "0 $ sec": $ sec; $ min = ($ min <10 )? "0 $ min": $ min; $ hour = ($ hour <10 )? "0 $ Hour": $ hour; $ day = ($ day <10 )? "0 $ Day": $ day; $ MON = ($ mon <9 )? "0 ". ($ mon + 1) :( $ mon + 1); $ year + = 1900; my $ now = "$ year $ mon $ day $ hour: $ min: $ sec "; return $ now ;}
Method 3:
print scalar gmtime ;print scalar localtime