I need to predict the next run of a daily job. For example, if my job runs everyday at 1:00:00 am, and my sysdate is Nov 7 11:20:00 am, then my next run will be at Nov 8 1:00:00 am
The below logic helps me to achieve the desired results. However, when i convert the date after adding no. days to the start date, unix considers the daylight saving and converts from PDT timezone to PST timezone and gives me a time lag of 1 hour. Instead of getting Nov 8 1:00:00 am, I am getting Nov 8 00:00:00 am as output.
I want to derive date without the day light savings. Can someone help me achieve this logic in UNIX?
CURR_DATE=`date "+%s"`
START_DATE=`date -d "19OCT2014 01:00:00" "+%s"` #start date when the job was run first
diff_quo=$(((($CURR_DATE - $START_DATE) / (86400))))
diff_quo=$(($diff_quo * 86400))
new_datetime=$(($START_DATE + $diff_quo + 86400 ))
DERIVED_DATE=`date -d"#$new_datetime" "+%b %d %H:%M:%S"`
Thanks,
Ekata
Related
I need help with this scenario:
1) Currently it is summer time. I need to create a time interval for June 9 Monday 6 PM - 7 PM EDT and every week after that until end of 2018. This interval will be for students to schedule appointments with a tutor. The client right now sends that as a request for creating start time at June 9 Mondays 2 PM UTC. (EDT is -4 hours offset) The server creates a start time in db for June 9 2 PM UTC and adds 7 days worth of milliseconds to create recurring
^ this causes an issue because of DST. Let's say it is right now November 5th (which is after daylights saving change). The DB still has Nov 5, 2 PM UTC saved as value. But because my timezone changed, instead of offsetting by 4 hours like I did on June, I offset by 5 hours. So the correct start time is "6 PM session in my timezone" becomes "7 PM my timezone". this is the error
the solution is either of one of two (or combination of both):
1) instead of adding 7 days worth of milisecond, you add 1 week worth of miliseconds depending on the user's timezone Currently, there's no way to extract a person's timezone based on utc offset (-400, which is right now in east coast USA, is also applicable to Canada, Carribeans, South America etc. We need to save a user's timezone as a string, rather than UTC offset count. There is an international standard for timezones)
2) ?? something else
I am trying to convert "30 Jun 17 5:08 pm -0500" to POSIX time format in R.
date <- c("30 Jun 17 5:08 pm -0500")
mydate <- as.POSIXct(date, format="%d %b %y %I:%M %p %z")
The returned result is "2017-06-30 18:08:00 EDT".
Obviously, the time is incorrect, it should be 17:08:00.
Your original time is from a -0500 timezone (5 hours behind UTC), which, assuming it was a standard US time zone, was likely Central Daylight Time, which has that offset. Your current timezone, Eastern Daylight Time, is -0400 (4 hours behind UTC).
In my case, since my computer is currently in CDT, I get the following result from your code:
mydate
## [1] "2017-06-30 17:08:00 CDT"
Which is as it should be, since my time zone matches the UTC offset that your time was originally from.
I have a few UNIX timestamps that I've been converting back and forth, and I notice that the last number of the timestamp would change without causing any difference in the date.
For example, if you convert this number to normal date:
1452120848 > 6-1-16 17:54
But if you convert it back:
6-1-16 17:54 > 1452120840
As you can see the last number was changed to a zero. I tried some of the online converters and discovered that the last number could be any number and the date wouldn't change. What does it mean?
The unix time is the time in seconds since 1970.
You don't convert the seconds part of your date, thus it's 'lost' - your numbers may differ by up to 60.
The timestamp of 1452120848 is actually: Wed Jan 6 22:54:08 2016
So you're missing 8 seconds.
The UNIX timestamp gives you the seconds since 1st January 1970 00.00.00 UTC. Since this is seconds and you are just printing up to minutes, the difference is not shown.
However, they are not the same date:
$ date -d#1452120848
Wed Jan 6 23:54:08 CET 2016
$ date -d#1452120840
Wed Jan 6 23:54:00 CET 2016
In ext-js ,
I have a data in millseconds ..eg;850248000000 for DOB field.
it is what i get from server side.
I need to convert this to Date format to be shown in a browser.
Time Zone at the Client Side should not affect the conversion.
Appreciate your help.
kp
The first thing to know would be what the time means(thanks #Teo). If it's epoch time in ms, the following might work for you
var d = new Date(850248000000)
console.log(d.toGMTString())
>>>Tue, 10 Dec 1996 20:00:00 GMT VM309:2
console.log(d.toLocaleString())
>>>12/10/1996 3:00:00 PM VM310:2
my_current_epoch=15684 equivalent time stamp is Thu, 01 Jan 1970 04:21:24
last_password_reset_epoch_time=15547 equivalent time stamp is Thu, 01 Jan 1970 04:19:07
I am not able to understand how difference of these two will give the days since last password reset.
As per my understanding epoch time is denoted in seconds that has elapsed since Jan 1,1970
Can someone please help me understanding this.
man 5 shadow on a Linux box says:
The date of the last password change is given as the number of days since Jan 1, 1970. The password may not
be changed again until the proper number of days have passed, and must be changed after the maximum number
of days. If the minimum number of days required is greater than the maximum number of day allowed, this
password may not be changed by the user.
So, you can find out to within 24 hours when a password was changed by multiplying the value from /etc/shadow by 86400 (the number of seconds in a day — but you didn't need me to tell you that, did you?).
For the values given (bc to the rescue):
15684*86400 = 1355097600
15547*86400 = 1343260800
And:
$ timestamp -u 1355097600 1343260800
1355097600 = Mon Dec 10 00:00:00 2012
1343260800 = Thu Jul 26 00:00:00 2012
$
Timestamp is my program; modern versions of date can handle this too. The -u means 'report in UTC (aka GMT)' rather than in my time zone.
"epoch" value in /etc/shadow = 15684
the seconds in 24 hours (because normally "epoch" value shows in seconds but for some reason (to make compact view, maybe) in /etc/shadow file "epoch" value displays in days, not in seconds) = 24 * 60 * 60 = 86400
And by multipliying these two numbers: 15684 (days) x 86400 (seconds per day); we will get the number 1355097600.
Afterwards, either using Epoch Converter by copy/paste the final result, you can get the date, or
just use date --date #$(( 15684 * 86400 )) command in cli