全部博文(279)
分类:
2007-11-27 16:05:45
Perl has a handy built-in function for finding the current date and time in your scripts. Keep in mind, though, that when we talk about finding the time, we're talking about the time that is currently set on the machine that's running the script. For instance, if you're running your Perl script on your local machine, localtime will return the current time you have set, and presumably set to your current timezone.
When you run the same script on a web server though, you may find that localtime there is off from localtime on your desktop system. The server might be in a different time zone, or be set incorrectly. Each machine may have a totally different idea of what localtime is and it may take some adjusting, either within the script or on the server itself, to get it to match up to what you're expecting.
The localtime function returns a list full of data about the current time, some of which will need to be adjusted. Run the program below and you'll see each element in the list printed on the line and separated by spaces.
#!/usr/local/bin/perlYou should see something similar to this, although the number could be very different. [blockquote shade=yes] 20 36 8 27 11 105 2 360 0 [blockquote] These elements of the current time are, in order:
@timeData = localtime(time);
print join(' ', @timeData);