epoch 밀리초란
epoch 밀리초는 1970년 1월 1일 00:00:00 UTC 이후의 밀리초를 셉니다. Unix 초와 같은 Unix 에포크를 쓰지만 정밀도가 세 자리 더 많습니다. 현대의 epoch 밀리초 값은 보통 13자리로, 1700000000000 같습니다.
millis를 날짜로 변환하는 법
값이 이미 밀리초라면 JavaScript Date가 바로 읽을 수 있습니다. 받는 도구가 초를 기대하면 먼저 1000으로 나누세요. 주된 실수는 잘못된 경계에서 곱하거나 나누는 것입니다.
- JavaScript: new Date(1700000000000).toISOString()
- Milliseconds to seconds: Math.floor(1700000000000 / 1000)
- Seconds to milliseconds: 1700000000 * 1000
- Java Instant: Instant.ofEpochMilli(1700000000000L)
- Python: datetime.fromtimestamp(ms / 1000, tz=timezone.utc)
Java와 데이터베이스에서 long을 날짜로
'long을 날짜로' 검색은 타임스탬프를 64비트 정수로 저장하는 Java, Kotlin, Android, 데이터베이스 export에서 자주 나옵니다. 값은 epoch 밀리초일 수도 있지만 초, 마이크로초, 나노초일 수도 있습니다. 변환 전에 자릿수를 확인하세요.
- 10자리: 아마 Unix 초
- 13자리: 아마 Unix 밀리초 또는 Java long 밀리초
- 16자리: 아마 마이크로초
- 19자리: 아마 나노초
- 열 이름에는 항상 단위를 붙이세요(예: created_at_ms)
왜 밀리초가 이상한 날짜로 변환되나
밀리초 값을 초로 다루면 아주 먼 미래 날짜가 됩니다. 초 값을 밀리초로 다루면 1970년 1월 근처 날짜가 됩니다. 자릿수가 가장 빠른 진단입니다.
- 1700000000000을 밀리초로 = 2023-11-14 22:13:20 UTC
- 1700000000000을 초로 = 라이브러리에 따라 서기 55840년 부근
- 1700000000을 초로 = 2023-11-14 22:13:20 UTC
- 1700000000을 밀리초로 = 1970-01-20 16:13:20 UTC
epoch 밀리초 FAQ
A milliseconds value treated as seconds becomes an extremely far-future date. A seconds value treated as milliseconds becomes a date near January 1970. The digits are the quickest diagnostic.
- 1700000000000 as milliseconds = 2023-11-14 22:13:20 UTC
- 1700000000000 as seconds = year 55840 range, depending on the library
- 1700000000 as seconds = 2023-11-14 22:13:20 UTC
- 1700000000 as milliseconds = 1970-01-20 16:13:20 UTC
Cross-language patterns for ms-to-date
The conversion is structurally the same in every language — divide by 1000 (carefully) or use a millisecond-aware constructor. The details that bite are precision loss and naming.
- JavaScript: new Date(1700000000000) — no division needed, Date is millisecond-based
- Python: datetime.fromtimestamp(1700000000000 / 1000, tz=timezone.utc) — float division, watch for precision loss
- Java: Instant.ofEpochMilli(1700000000000L) — exact millisecond precision preserved
- PostgreSQL: SELECT to_timestamp(1700000000000.0 / 1000) — to_timestamp expects seconds, not milliseconds
- SQLite: SELECT datetime(1700000000000 / 1000, 'unixepoch') — integer division drops fractional seconds
- Go: time.UnixMilli(1700000000000) — added in Go 1.17 specifically to avoid the seconds-vs-ms mix-up
- Ruby: Time.at(0, 1700000000000, :millisecond) for exact ms precision
- C#: DateTimeOffset.FromUnixTimeMilliseconds(1700000000000L).UtcDateTime
Related articles
FAQ
- Is epoch time in ms the same as Unix timestamp?
- It uses the same epoch, but the unit is milliseconds instead of seconds. Classic Unix timestamp usually means seconds.
- How many digits is an epoch millisecond timestamp?
- For current dates, epoch milliseconds are usually 13 digits.
- Does JavaScript use milliseconds or seconds?
- JavaScript Date uses milliseconds. Date.now() returns epoch milliseconds.
- How do I convert a Java long timestamp to a date?
- If the long is epoch milliseconds, use Instant.ofEpochMilli(value); if it is epoch seconds, use Instant.ofEpochSecond(value). Check the digit count first — 13 digits is usually milliseconds, 10 digits is usually seconds.