i use solaris10 server. I need yesterdays 00:00:00 time in epoc and yesterdays 25:59:59…
- User
i use solaris10 server. I need yesterdays 00:00:00 time in epoc and yesterdays 25:59:59 time in epoc. I live in GMT+3. Use perl
- Assistant
To calculate yesterday's
00:00:00and25:59:59times in epoch format (Unix timestamp) in Perl, you can use theTime::Localmodule, which is part of the core Perl distribution. Here's how you can achieve this on a Solaris 10 server.First, make sure you have Perl installed on your server. Then, you can use the following script:
perl - User
do it in one line for each time
- Assistant
Sure! You can achieve the calculations for yesterday's
00:00:00and25:59:59in epoch format using Perl in a one-liner for each. Here are the one-liners you can use:-
For yesterday's
00:00:00in epoch:perlperl -e 'use Time::Local; print timelocal(0, 0, 0, (localtime(time - 86400))[3], (localtime(time - 86400))[4], (localtime(time - 86400))[5]) - (3 * 3600), "\n";' -
For yesterday's
25:59:59in epoch:perlperl -e 'use Time::Local; print timelocal(59, 59, 1, (localtime(time - 86400))[3], (localtime(time - 86400))[4], (localtime(time - 86400))[5]) - (3 * 3600), "\n";'
Explanation:
- localtime(time - 86400): This gets the local time of yesterday.
- : This converts the given time (0 hours, 0 minutes, etc.) into epoch time.
-
- User
this gives two days ago and09:00 i need yesterdays 00:00
- Assistant
Apologies for the confusion. To get yesterday's
00:00:00and25:59:59correctly, you need to ensure that you're setting the right date components when adjusting for the previous day's date. Here's how you can do that correctly in one line for each time:- For yesterday's
00:00:00in epoch:
perlperl -e 'use Time::Local; my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time - 86400); print timelocal(0, 0, 0, $mday, $mon, $year), "\n";'- For yesterday's
25:59:59in epoch:
perlperl -e 'use Time::Local; my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time - 86400); print timelocal(59, 59, 1, $mday, $mon, $year), "\n";'Explanation:
- For yesterday's
- User
perl -e 'use Time::Local; my (min,mday,year) = localtime(time - 86400); print timelocal(0, 0, 0, mon, $year), "\n";' is ok the other is not giving yesterdays 23:59:59
- Assistant
I apologize for the confusion. You're correct that the
25:59:59would not yield the expected result, as it needs to be interpreted as the equivalent ofyesterday's 23:59:59in terms of Unix time.To represent
yesterday's 23:59:59, you should indeed pass that hour and minute directly. Here’s the corrected command:For yesterday's
00:00:00in epoch:perlperl -e 'use Time::Local; my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time - 86400); print timelocal(0, 0, 0, $mday, $mon, $year), "\n";'For yesterday's
23:59:59in epoch:perlperl -e 'use Time::Local; my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time - 86400); print timelocal(59, 59, 23, $mday, $mon, $year), "\n";'Explanation:
- User
OK i use below but i need in milisecond yesterdayStartTimeEpoc=sec,hour,mon,mday, year), "\n";') yesterdayEndTimeEpoc=sec,hour,mon,mday, year), "\n";')
- Assistant
To convert the epoch time to milliseconds in your Perl one-liners, you simply need to multiply the result by 1000. Here's how you can modify your existing commands to achieve that:
For yesterday's
00:00:00in milliseconds:bashyesterdayStartTimeEpoc=$(perl -e 'use Time::Local; my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time - 86400); print timelocal(0, 0, 0, $mday, $mon, $year) * 1000, "\n";')For yesterday's
23:59:59in milliseconds:bashyesterdayEndTimeEpoc=$(perl -e 'use Time::Local; my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time - 86400); print timelocal(59, 59, 23, $mday, $mon, $year) * 1000, "\n";')Summary:
- In both one-liners, we are multiplying the epoch time (which is returned in seconds) by
1000to convert it into milliseconds. - The output will store the milliseconds since the epoch for both and .
- In both one-liners, we are multiplying the epoch time (which is returned in seconds) by