How do I get the current UNIX timestamp (Unix timestamp) in different programming languages?

Source: Internet
Author: User
Tags postgresql

The Unix time stamp (Unix timestamp), or Unix time, or POSIX time, is a time representation defined as the total number of seconds from GMT January 01, 1970 00:00 00 seconds to now. Unix timestamps are used not only in UNIX systems, Unix-like systems, but also in many other operating systems.

A significant portion of the operating system is currently using 32-bit binary numbers to represent time. UNIX timestamps of such systems can be used up to Greenwich Mean time of January 19, 2038 03:14 07 seconds (binary:01111111 11111111 11111111 11111111). After a second, the binary number will change to 10000000 00000000 00000000 00000000, an overflow error, causing the system to misunderstand the time of December 13, 1901 20:45 52 seconds. This is likely to cause a software failure, or even a system crash. Systems that use 64-bit binary numbers to represent time (up to GMT 292,277,026,596, December 04, 15:30, 08 seconds) do not experience this kind of overflow.

How to get the current UNIX timestamp in different programming languages ( Unix Timestamp)?
Java Time
Javascript Math.Round (New Date (). GetTime ()/1000)
GetTime () The unit of return value is 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 Get UNIX timestamp: Time.now or Time.new
Show Unix timestamp: Time.now.to_i
SQL Server SELECT DATEDIFF (S, ' 1970-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 "Print Time"
How to implement UNIX timestamps in different programming languages ( Unix Timestamp) → Normal time?
Java String date = new Java.text.SimpleDateFormat ("Dd/mm/yyyy HH:mm:ss"). Format (new java.util.Date (Unix timestamp * 1000))
Javascript First var unixtimestamp = new Date (Unix timestamp *) and then Commontime = unixtimestamp.tolocalestring ()
Linux Date-d @Unix Timestamp
Mysql From_unixtime (Unix timestamp)
Perl First my $time = Unix timestamp 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, ' 1970-01-01 00:00:00 ')
Vbscript/asp DATEADD ("s", Unix timestamp, "01/01/1970 00:00:00")
Other operating systems
(If Perl is installed in the system)
Command line status: Perl-e "Print scalar (localtime (Unix timestamp))"

How do I get the current UNIX timestamp (Unix timestamp) in different programming languages?

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.