Unix Timestamp by Language
Copy-ready code snippets for getting and converting Unix timestamps in your language. Each page covers seconds, milliseconds, and date parsing — no external libraries required where possible.
JavaScriptJavaScript's Date API works in milliseconds internally. Use Date.now() to get the current timestamp — divide by 1000 for seconds, or keep as-is for milliseconds.View snippets →PythonPython's time module gives you the current Unix timestamp as a float (seconds with decimal precision). Use int() to truncate to whole seconds.View snippets →JavaJava has two main ways to get Unix timestamps: the legacy System.currentTimeMillis() (milliseconds) and the modern java.time.Instant API (Java 8+, recommended).View snippets →PHPPHP's time() function returns the current Unix timestamp in seconds. For milliseconds, use microtime(). DateTime and Carbon are popular for date arithmetic.View snippets →GoGo's time package provides Unix() and UnixMilli() methods on time.Time. These are simple, idiomatic, and don't require external dependencies.View snippets →RubyRuby's Time class has built-in Unix timestamp support. Time.now.to_i gives you seconds; multiply by 1000 for milliseconds. Rails adds extra helpers via ActiveSupport.View snippets →RustRust's standard library provides SystemTime for Unix timestamps. For richer date handling, the chrono crate is the community standard.View snippets →SwiftSwift uses Date and TimeInterval (a Double of seconds) for timestamps. On Apple platforms, CFAbsoluteTime is relative to Jan 1 2001 — always use Date.timeIntervalSince1970 for Unix epoch compatibility.View snippets →KotlinKotlin on the JVM uses java.time.Instant (recommended, Java 8+) or System.currentTimeMillis(). In Kotlin Multiplatform, kotlinx-datetime provides a cross-platform API.View snippets →C#C# uses DateTimeOffset.UtcNow for timezone-safe timestamps. ToUnixTimeSeconds() and ToUnixTimeMilliseconds() give you Unix timestamps directly — no math required.View snippets →Bash / ShellBash can get Unix timestamps with the date command (GNU coreutils or macOS BSD). These one-liners are useful in scripts, cron jobs, and DevOps automation.View snippets →TypeScriptTypeScript uses the same Date API as JavaScript but adds static typing. Adding explicit type annotations prevents common timestamp bugs — like accidentally mixing seconds and milliseconds — at compile time.View snippets →CC's time() function has returned Unix timestamps since the 1970s — it's where the epoch convention originated. For sub-second precision, use clock_gettime() with CLOCK_REALTIME.View snippets →DartDart's DateTime class uses milliseconds internally — just like JavaScript. Use DateTime.now().millisecondsSinceEpoch for milliseconds, or integer-divide by 1000 for seconds. Flutter and server-side Dart both use the same API.View snippets →PowerShellPowerShell uses [DateTimeOffset]::UtcNow for Unix timestamps. The ToUnixTimeSeconds() and ToUnixTimeMilliseconds() methods are available in .NET 4.6+ and all PowerShell 5.1+ environments.View snippets →ElixirElixir uses DateTime and System.system_time/1 for Unix timestamps. Both return integers in the time unit you specify (:second, :millisecond, :microsecond) — making unit conversion explicit and clear.View snippets →PerlPerl has built-in Unix timestamp support via the time() function, which returns the current epoch in seconds. The POSIX and DateTime modules provide more advanced conversion and formatting utilities.View snippets →ScalaScala runs on the JVM and shares Java's time libraries. Use java.time.Instant (preferred since Java 8) or System.currentTimeMillis() for Unix timestamps. The Scala standard library has no dedicated time API.View snippets →LuaLua's os library provides Unix timestamp support via os.time(). It returns seconds since the epoch by default. For millisecond precision, the socket library (LuaSocket) or platform-specific C extensions are needed.View snippets →RR stores dates as numeric values internally. Use Sys.time() to get the current timestamp and as.numeric() to convert to a Unix epoch in seconds. The lubridate package (tidyverse) simplifies date arithmetic significantly.View snippets →SQLSQL timestamp functions vary by database engine. MySQL, PostgreSQL, SQLite, and SQL Server each have different built-in functions for working with Unix epoch values. The core concept is the same: seconds since 1970-01-01 00:00:00 UTC.View snippets →
Need to convert a specific timestamp? Use the live converter — paste any epoch value and see the human-readable date instantly.
← Open the converter