言語 | コード |
---|---|
Swift | NSDate().timeIntervalSince1970 |
Go | import ( "time" ) int64(time.Now().Unix()) |
Java | // pure java System.currentTimeMillis() / 1000 // joda java DateTime.now().getMillis() / 1000 // java >= 8 Instant.now().getEpochSecond() |
C | #include // ... struct timeval tv; gettimeofday(&tv, NULL); // 秒: tv.tv_sec // 毫秒: tv.tv_sec * 1000LL + tv.tv_usec / 1000 |
JavaScript | Math.round(new Date() / 1000) |
Objective-C | [[NSDate date] timeIntervalSince1970] |
MySQL | SELECT unix_timestamp(now()) |
SQLite | SELECT strftime('%s', 'now') |
PostgreSQL | |
SQL Server | |
Erlang | calendar:datetime_to_gregorian_seconds(calendar:universal_time())-719528*24*3600. |
PHP | // pure php time(); // carbon php use CarbonCarbon; Carbon::now()->timestamp; |
Python | import time time.time() import arrow arrow.utcnow().timestamp |
Ruby | Time.now.to_i |
Groovy | (new Date().time / 1000).longValue() |
Lua | os.time() |
.NET/C# | DateTimeOffset.UtcNow.ToUnixTimeSeconds(); |
Dart | (new DateTime.now().millisecondsSinceEpoch / 1000).truncate() |
Unix/Linux(Shell) | date +%s |
Perl | time |
VBScript/ASP | |
Other |