Dave's Brain

Browse - Programming Tips - What's an easy way to display the time?

Date: 2012mar18
Language: perl

Q.  What's an easy way to display the time?

A.  If you aren't picky about the exact way it looks, use asctime() like this:

# Required to use asctime(). # But every installation is going to have this. use POSIX; # Obtain the current time. # Or you could use a file's modify time, etc. my $time = time(); # Convert the time to the local timezone with localtime(). # Format it with asctime(). # Then print it. print asctime(localtime($time));
Example output:
Sun Mar 18 06:27:28 2012

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.