Perl is one of the most feature-rich programming languages. Perl is portable and cross-platform. Perl can run on over 100 platforms with highly integrated text processing ability. Perl contains the features of different languages like C, sed, awk, and sh etc. which makes the Perl more useful and productive.
Perl is an easy-to-use language. It is intended to be efficient and complete rather than elegant and minimal. Perl supports some major programming paradigms together with object-oriented, procedural, and practical.
Date and Time in Perl can be handled by using a predefined module of Perl called DateTime module. DateTime is a class for the representation of various combinations of dates and times. DateTime module in Perl represents the New Style calendar, extended backward in time before its creation (in 1582).
This is typically referred to as the “proleptic Gregorian calendar”.
In this calendar, the first day of the calendar (the epoch), is the first day of year 1, which corresponds to the date which was (incorrectly) believed to be the birth of Jesus Christ.
Syntax: use DateTime;
localtime() function in Perl returns the current date and time of the system, if called without passing any argument.
Local Time of the System : Fri Nov 15 07:21:05 2019
Creating a Timestamp
A timestamp in Perl is used to display the current Date and Time of the day. Data displayed by timestamp is sometimes accurate to a fraction of seconds.
Timestamp can be created by creating a DateTime object and then calling the now constructor.
A DateTime object can also be created by providing all the details part wise like date, hour, minute, second, etc. Default value for variables with no value passed is ‘0‘.
Finding GMT Time
GMT stands for Greenwich Mean Time, which is the mean solar time at the Royal Observatory in Greenwich, London. GMT is the same during all the year and is not affected by Daylight Saving Time(Summer Time) clock changes.
Perl provides a predefined function for calculation and representation of GMT, which is
gmtime(). This function works similar to
localtime() function but the only difference is that the time values are localized for the Greenwich time zone only.
Date and time in GMT: Fri Nov 15 11:10:05 2019
Formatting Date and Time
localtime() function can also be used to print date and time in various formats as per the user’s requirement. This formatting can be easily done by using
Time Format - HH:MM:SS 11:38:06
Epoch time refers to the number of seconds passed after a specific date and time. The specific date and time used to calculate epoch time vary from OS to OS. For example, for POSIX or UNIX systems, this date is January 1, 1970. Since this time varies from system to system, one cannot assume epoch time for any system.
- Perl | Basic Syntax of a Perl Program
- Perl Tutorial - Learn Perl With Examples
- Getting the current date and time with timestamp in local and other timezones in Golang
- How to get the current date and time in seconds?
- Ruby Date and Time
- How to Get Current Date and Time in Various Format in Golang?
- Working with Date and Time in Julia
- Convert timestamp to readable date/time in PHP
- How to Print Specific date-time in Golang?
- Difference between Turn Around Time (TAT) and Waiting Time (WT) in CPU Scheduling
- Difference between Seek Time and Disk Access Time in Disk Scheduling
- Difference between Seek Time and Transfer Time in Disk Scheduling
- Difference between Transfer Time and Disk Access Time in Disk Scheduling
- Difference between Arrival Time and Burst Time in CPU Scheduling
- Perl Installation and Environment Setup in Windows, Linux, and MacOS
- Perl | Removing leading and trailing white spaces (trim)
- Perl | undef and the defined function
- Perl | Variables and its Types
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.