DATE COMMAND IN LINUX
# The Date Command in Linux Command Prompt can be used to simply display the Systems Date along with the Time, Day, Year & Month. Also this Command can be used to do Interesting Hacks with Time which we will see Further.
# To implement this Command, The Prerequisites are :
a) To Have LINUX OS in System.
b) You should have an account with Root id as credentials to log in as Privilege user.
c) And Simply a Command Prompt to access using the Terminal.
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
*************Lets Simply Start by Displaying the Date***********
To Print the Date, Day, Time, Month & Year, type date as the command and thus will be printed as Shown in Below Image.
#) We can Print the Year, Month, Minute, seconds(showing Epoch) using the Syntax as Shown in image below Respectively.
#) Now, Lets Make it More Interesting, LINUX keep the ability to print information or any text in Dialogue Box using Zenity Command by using the #) Syntax : zenity — info — text=”THE CURRENT YEAR IS $(date +%Y)”
#) Here we are only printing the year but the same syntax can be used to print the month by $(date +%m), date by $(date +%d) and so on.
#) Point to be noted here is because of $ sign, the date is being taken as a Command instead of text/string to print Successfully.
*****These are Some of the Common Commands used in Date*****
%D
– Display date as mm/dd/yy%Y
– Year (e.g., 2020)%m
– Month (01-12)%B
– Long month name (e.g., November)%b
– Short month name (e.g., Nov)%d
– Day of month (e.g., 01)%j
– Day of year (001-366)%u
– Day of week (1-7)%A
– Full weekday name (e.g., Friday)%a
– Short weekday name (e.g., Fri)%H
– Hour (00-23)%I
– Hour (01-12)%M
– Minute (00-59)%S
– Second (00-60)
*******************Change Date/Time in LINUX*****************
#) To Change the Date/Time, we use the set command along with the year_month_day & Time As shown in the Diagram Below.
Syntax : date — set=”20211013 12:00”
********************Display Past Date & /Time******************
#) To Display Past Date & Time, in this case to display yesterdays date & Time, use the Syntax : date — date=”Yesterday”
#) Similarly in place of yesterday you can use “10 sec ago”, “2 year ago” to Display the Respective.
******************Display Future Date & /Time******************
#) In LINUX date Command also keep the ability to calculate and display future dates by the Same Syntax as Above but future Time example :
#) Syntax : date — date=”Tomorrow” to display the tomorrows date/time or
date — date=”6 days” to display the date/time of future i.e after 6 days.
#) The below Image gives Implemented Example
****************Display Specific Regions Time Zone**************
#) LINUX also have this ability to Display Time Zones From Different Countries and also it Can Predict the Future Time and Date for Specific Region For Example :
#) To Display Specific RegionsTime Zone :
#) Syntax : TZ=”Africa/Accra” date (TO DISPLAY AFRICAS TIME) TZ=”America/Costa_rica” date (TO DISPLAY AMERICAS TIME)
#)And thus can be configured based on the country input.
#) Also we Can Display the Future Time for any Specific Country for Example :
#) Syntax : date -d ‘TZ=”Australia/Sydney” 04:30 next Monday’ to Display The Time and Date of Upcoming Monday & here the 04:30 is mentioned to calculate the Time based on the Requirement i.e 04:30 will be 01:00 IST according to the Australian Time Zone.
***********************Display Epoch Time*********************
#) Displaying Epoch Time is Simply Displaying the Number of seconds that have passed & Still Continuing since January 1, 1970, at 00:00:00 UTC.
#) Syntax : date +%s
#) Similarly we can Display the epoch Time from the date and day which we specify for example :
#) Syntax : date -d “2021–09–10” +”%s” so will Display the Time in Seconds.