Obtain the current Unix timestamp in different programming languages

Source: Internet
Author: User
Tags iso 8601
The Unix timestamp (Unixepoch, Unixtime, POSIXtime, or Unixtimestamp) is the number of seconds elapsed since January 1, January 1, 1970 (midnight UTC/GMT), regardless of the leap second. The UNIX timestamp 0 follows the ISO8601 standard: 1970-01-01T00: 00: 00Z. one hour is expressed as the UNIX timestamp format: 3600 seconds; one

Unix timestamp (Unix epoch, Unix time, POSIX time or Unixtimestamp)

It is the number of seconds that have elapsed since January 1, January 1, 1970 (midnight UTC/GMT), regardless of the leap second.

The UNIX timestamp 0 follows the ISO 8601 standard: 1970-01-01T00: 00: 00Z. the UNIX timestamp format for one hour is 3600 seconds. The UNIX timestamp for one day is 86400 seconds. the leap second is not calculated.

In most UNIX systems, the UNIX timestamp is stored as 32-bit, which may cause the 2038 issue or Y2038.

Time seconds 1 minute 60 1 hour 3600 1 day 86400 1 week 604800 January (30.44 days) 2629743 1 year (365.24 days) 31556926 how do I obtain the current Unix timestamp (Unix timestamp) in different programming languages )?

Java time JavaScript Math. round (newDate (). GetTime ()/1, 1000)

GetTime () returns the value in milliseconds Microsoft. NET/C # epoch = (DateTime. Now. ToUniversalTime (). Ticks-621355968000000000)/10000000 MySQL SELECT unix_timestamp (now ())

Perl time PHP time ()

PostgreSQL SELECT extract (epoch FROM now ())

Python first import time and then time. time ()

Ruby obtains the Unix timestamp: Time. now or Time. new: Unix timestamp: Time. now. to_iSQL Server select datediff (s, '2017-01-01 00:00:00 ', GETUTCDATE ())

Unix/Linux date + % s VBScript/ASP DateDiff ("s", "01/01/1970 00:00:00", Now ())

Other operating systems (if Perl is installed in the system) Command Line status: perl-e "printtime" how to implement Unix Timestamps (Unix timestamp) in different programming languages → Normal time?

Java String date = newjava. text. SimpleDateFormat ("dd/MM/yyyy HH: mm: ss "). Format (newjava. util. Date (Unix timestamp * 1000 ))

JavaScript first var unixTimestamp = new Date (Unix timestamp * 1000) and then commonTime = unixTimestamp. toLocaleString ()

Linux date-d @ Unix timestamp MySQL from_unixtime (Unix timestamp)

Perl first my $ time = Unix timestamp and then my ($ sec, $ min, $ hour, $ day, $ month, $ year) = (localtime ($ time) [0, 1, 2, 3, 4, 5, 6] PHP date ('R', Unix timestamp)

PostgreSQL select timestamp with time zone 'epoch' + Unix timestamp) * INTERVAL '1 second'; Python first import time and then time. gmtime (Unix timestamp)

Ruby Time. at (Unix timestamp)

SQL Server DATEADD (s, Unix timestamp, '2017-01-0100:00:00 ')

VBScript/ASP DateAdd ("s", Unix timestamp, "01/01/197000: 00: 00 ")

Other operating systems (if Perl is installed in the system) Command Line status: perl-e "printscalar (localtime (Unix timestamp )) "How does one implement normal time → Unix timestamp (Unixtimestamp) in different programming languages )?

Java long epoch = newjava. text. SimpleDateFormat ("dd/MM/yyyy HH: mm: ss "). Parse ("01/01/197001: 00: 00"); JavaScript var commonTime = newDate (Date. UTC (year, month-1, day, hour, minute, second ))

MySQL SELECT unix_timestamp (time)

Time format: YYYY-MM-DD HH: MM: SS or YYMMDD or YYYYMMDD Perl first useTime: Local then my $ time = timelocal ($ sec, $ min, $ hour, $ day, $ month, $ year); PHP mktime (hour, minute, second, day, month, year)

PostgreSQL SELECT extract (epoch FROM date ('yyyy-MM-DDHH: MM: SS'); Python first import time and then int (time. mktime (time. strptime ('yyyy-MM-DD HH: MM: SS', '% Y-% m-% d % H: % M: % S ')))

Ruby Time. local (year, month, day, hour, minute, second)

SQL Server SELECT DATEDIFF (s, '2017-01-01 00:00:00 ', time)

Unix/Linux date + % s-d "Jan 1, 1970 00:00:01" VBScript/ASP DateDiff ("s", "01/01/1970 00:00:00", time)

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.