SHELL get the number of milliseconds

Source: Internet
Author: User

Conditions are required for exporting data from mongodb

Currently, time is stored in milliseconds. Therefore, you must obtain the number of milliseconds from the shell.

The first thing to say is the + % s parameter of the date command.

I searched the internet, and many people spread messages by mistake. date + % s is millisecond!

Wrong. It's a big mistake, because man said so.

% S seconds since 1970-01-01 00:00:00 UTC

Therefore, the output is from 00:00:00 on January 1, January 1, 1970 to the current second, not in milliseconds.

# Date-d "2014-04-10 00:00:00" + % s
1397059200

So it takes milliseconds to retrieve the x1000.

1397059200000

Then I made another experiment.

Obtain the number of milliseconds in oracle and sqlplus.

Sys @ TESTM> set numwidth 30 // if this parameter is not set, sqlplus uses science to output the result.

Sys @ TESTM> SELECT TO_NUMBER (TO_DATE ('2017-04-10 00:00:00 ', 'yyyy-MM-DD HH24: MI: ss ') -TO_DATE ('1970-01-01 00:00:00 ', 'yyyy-MM-DD HH24: MI: ss') * 24*60*60*1970 as time from dual;

TIME
------------------------------
1397088000000

The preceding SQL statement uses to_date to calculate the number of days from January 1, January 1, 1970 to the current time, multiply by 24 hours to get the hour, * 60*60 to get the second, and then * 1000 to get the millisecond.

However, the number of milliseconds in oracle is different from that in shell!

Let's look back at the explanation of the "date" command % s in man. The last three letters are correct. UTC is the English time!

The time in the UK is eight hours slower than that in Beijing.

1397059200000 + 8x60 X60 x 1000 = 1397088000000

You can also obtain the following information:

# Date-d "2014-04-10 08:00:00" + % s
1397088000x1000

= 1397088000000

######################################## ########

Simple Maintenance

Reprinted please indicate the source

Author: john

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.