Loading...
Loading...
Complete guide to working with timestamps in Java. Learn modern Java 8+ time API, timezone handling, and best practices. Copy-paste ready code examples.
Complete guide to working with timestamps in Java. Modern Java 8+ API and legacy approaches.
Get current Unix timestamp in milliseconds and seconds
// Method 1: System.currentTimeMillis() (Recommended)
long timestampMs = System.currentTimeMillis();
System.out.println(timestampMs); // 1729584000000
// Method 2: Instant.now() (Java 8+)
import java.time.Instant;
long timestampMs2 = Instant.now().toEpochMilli();
// Get timestamp in seconds
long timestampSec = System.currentTimeMillis() / 1000;
// Or using Instant
long timestampSec2 = Instant.now().getEpochSecond();Convert Unix timestamp to Date object
import java.util.Date;
import java.time.Instant;
// From milliseconds (legacy Date)
Date date = new Date(1729584000000L);
System.out.println(date); // Mon Oct 22 01:20:00 UTC 2024
// From seconds (convert to milliseconds)
Date dateFromSec = new Date(1729584000L * 1000);
// Using Instant (Java 8+, recommended)
Instant instant = Instant.ofEpochMilli(1729584000000L);
System.out.println(instant); // 2024-10-22T01:20:00Z
// From seconds using Instant
Instant instantFromSec = Instant.ofEpochSecond(1729584000L);Convert Date objects to Unix timestamps
import java.util.Date;
import java.time.LocalDateTime;
import java.time.ZoneId;
// Legacy Date to timestamp
Date date = new Date();
long timestamp = date.getTime();
// LocalDateTime to timestamp (Java 8+)
LocalDateTime ldt = LocalDateTime.now();
long timestampMs = ldt.atZone(ZoneId.systemDefault())
                      .toInstant()
                      .toEpochMilli();
// Specific date to timestamp
LocalDateTime specific = LocalDateTime.of(2024, 10, 22, 1, 20, 0);
long specificTimestamp = specific.atZone(ZoneId.of("UTC"))
                                 .toInstant()
                                 .toEpochMilli();System.currentTimeMillis()Instant.now().toEpochMilli()Instant.now().getEpochSecond()new Date(timestamp)Instant.ofEpochMilli(ms)Instant.ofEpochSecond(sec)DateTimeFormatter.ISO_INSTANTofPattern("yyyy-MM-dd")SimpleDateFormat (legacy)Instant (UTC point in time)ZonedDateTime (with TZ)LocalDateTime (no TZ)了解更多关于这个强大工具
此工具为您的时间戳需求提供基本功能。
旨在帮助您高效处理时间戳。
节省时间并提高时间戳操作的准确性。
Discover what makes this tool powerful
Professional java timestamp with comprehensive functionality. Industry-leading java timestamp providing accurate results and advanced features for all your needs.
Lightning-fast java timestamp with real-time results. Optimized java timestamp algorithms providing immediate accurate calculations and conversions.
All java timestamp operations happen locally in your browser. No data sent to servers, ensuring complete privacy for your operations.
Intuitive java timestamp interface designed for ease of use. Clear displays and helpful guides make the java timestamp accessible to everyone.
Java Timestamp working across all platforms and browsers. Compatible java timestamp supporting desktop, mobile, and tablet devices.
Completely free java timestamp with no registration required. Full-featured java timestamp available at no cost with unlimited usage.
专业级时间戳处理,企业级可靠性
简单步骤有效使用此时间戳工具
在工具提供的输入字段中输入您的时间戳或日期值。
选择您首选的输出格式和任何转换的附加选项。
以高准确性和精度即时查看转换结果。
将结果复制到剪贴板,并在您的应用程序或项目中使用。
Explore more timestamp conversion and calculation tools