-
Notifications
You must be signed in to change notification settings - Fork 5
/
date-time-info.sh
67 lines (47 loc) · 1.92 KB
/
date-time-info.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Demo shell script of getting date, time information
# Written by Ye Kyaw Thu, LST Lab., NECTEC, Thailand
# Last updated: 8 Aug 2020
# How to run: bash ./date-time-info.sh
Day=`date +%d`;
Month=`date +%m`;
Year=`date +%Y`;
mmWeekday=`date +%A`;
Hour=`date +%H`;
Minute=`date +%M`;
Second=`date +%S`;
# %x locale's date representation (e.g., 12/31/99)
localDate=`date +%x`;
# %X locale's time representation (e.g., 23:13:48)
#localTime=`date +%X`;
# %r locale's 12-hour clock time (e.g., 11:11:04 PM)
localTime12=`date +%r`;
# %R 24-hour hour and minute; same as %H:%M
localTime24=`date +%r`;
# %B locale's full month name (e.g., January)
localMonth=`date +%B`;
# %c locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
localDateTime=`date +%c`;
echo "Output of the date command:";
echo `date`;
echo "==========";
echo "Current local's date is: $localDate";
echo "Current local's 12-hour clock time is: $localTime12";
echo "Current local's 24-hour hour and minute is: $localTime24";
echo "Current Date: $Day ရက် $Month လ $Year ခုနှစ် ($mmWeekdayနေ့)";
echo "Current Time: $Hour နာရီ $Minute မိနစ် $Second စက္ကန့်";
echo "Current local month: $localMonth";
echo "Current local date and time: $localDateTime";
echo "=========="
#To print the date of the day before yesterday:
twoDaysAgo=`date --date='2 days ago'`;
echo "The date of the day before yesterday: $twoDaysAgo";
#To print the date of the day three months and one day hence:
SixMonthFifteenDay=`date --date='6 months 15 day'`;
echo "The date of the day six months and 15 day: $SixMonthFifteenDay";
#To print the day of year of Christmas in the current year:
ChristmasDate=`date --date='25 Dec' +%j`;
echo "The day of year of Christmas in the current year: $ChristmasDate";
#Someone's birthday
yBirthday=`date --date='25 April' +%x`;
echo "Someone's Birthday in the current year: $yBirthday";