

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Current Date and Time in Perl
Let's start with localtime() function in Perl, which returns values for the current date and time if given no arguments. Following is the 9-element list returned by the localtime function while using in list context −
sec, # seconds of minutes from 0 to 61 min, # minutes of hour from 0 to 59 hour, # hours of day from 0 to 24 mday, # day of month from 1 to 31 mon, # month of year from 0 to 11 year, # year since 1900 wday, # days since sunday yday, # days since January 1st isdst # hours of daylight savings time
Try the following example to print different elements returned by localtime() function −
Example
#!/usr/local/bin/perl @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); @days = qw(Sun Mon Tue Wed Thu Fri Sat Sun); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); print "$mday $months[$mon] $days[$wday]\n";
Output
When the above code is executed, it produces the following result −
16 Feb Sat
If you will use localtime() function in the scalar context, then it will return date and time from the current time zone set in the system. Try the following example to print the current date and time in full format −
Example
#!/usr/local/bin/perl $datestring = localtime(); print "Local date and time $datestring\n";
Output
When the above code is executed, it produces the following result −
Local date and time Sat Feb 16 06:50:45 2013
- Related Questions & Answers
- Format Date and Time in Perl
- Get current time and date on Android
- MySQL - Insert current date/time?
- Java Program to Display current Date and Time
- How to get current time and date in C++?
- How to get current date and time in Python?
- How to get current date and time in JavaScript?
- Set current date and time to timestamp in MySQL
- How to print current date and time using Python?
- How to get current date and time using JavaScript?
- C++ Program to print current Day, Date and Time
- Get current date/time in seconds - JavaScript?
- How to get the current date and time in Java?
- Java Program to Get Current Date/Time
- How to insert current date/time in MySQL?
Advertisements