How do you read the system time and date in Perl?

后端 未结 5 1429
太阳男子
太阳男子 2021-01-11 17:13

I need to read the system clock (time and date) and display it in a human-readable format in Perl.

Currently, I\'m using the following method (which I found here):

5条回答
  •  情深已故
    2021-01-11 17:24

    You can use localtime to get the time and the POSIX module's strftime to format it.

    While it'd be nice to use Date::Format's and its strftime because it uses less overhead, the POSIX module is distributed with Perl, and is thus pretty much guaranteed to be on a given system.

    use POSIX;
    print POSIX::strftime( "%A, %B %d, %Y", localtime());
    # Should print something like Wednesday, January 28, 2009
    # ...if you're using an English locale, that is.
    # Note that this and Date::Format's strftime are pretty much identical
    

提交回复
热议问题