Home > Blockchain >  Linux Date Function forward/backward time
Linux Date Function forward/backward time

Time:12-04

Is there an option of date function?

How do I get LOAD_TEST_START to be 2 minutes forward?

How do I get LOAD_TEST_END to be 2 minutes back?

LOAD_TEST_START=$(date -u  %FT%TZ)
LOAD_TEST_END=$(date -u  %FT%TZ)

CodePudding user response:

Not sure if this is what you want, but you can get the current epoch value and then add/subtract 120 seconds (2 minutes) from it and convert the results back to date.

dateval=`date  %s`
echo "orig "`date -d @$dateval  %FT%T%Z`

start=`expr $dateval   120`
end=`expr $dateval - 120`

LOAD_TEST_START=`date -d @$start  %FT%T%Z`
LOAD_TEST_END=`date -d @$end  %FT%T%Z`

echo "start "$LOAD_TEST_START
echo "end "$LOAD_TEST_END

CodePudding user response:

This answer helped me and works on the linux-version of date.

LOAD_TEST_START=$(date  %FT%TZ -d "2 minutes ago")
LOAD_TEST_END=$(date  %FT%TZ -d "2 minutes")

On macos/FreeBSD one can use

LOAD_TEST_START=$(date -v 2M  %FT%TZ)
LOAD_TEST_END=$(date -v-2M  %FT%TZ)
  • Related