Por qué esta página
A menudo recibes timestamps en segundos (10 dígitos), milisegundos (13), microsegundos (16) o nanosegundos (19). Esta página te da reglas completas, fragmentos listos para usar y enlaces al convertidor completo para que puedas transformar cualquier epoch a ISO 8601 / RFC 3339 sin adivinar la precisión.
Inicio rápido (flujo MVP)
- Pega el timestamp (detectamos automáticamente longitud y precisión).
- Elige zona horaria:
UTCo desplazamiento personalizado (ej.,UTC+01:00). - Obtén salida ISO 8601 / RFC 3339, luego copia con un clic.
- ¿Necesitas integrarlo? Copia un fragmento de código abajo.
Prueba la herramienta interactiva: Convertidor Timestamp → ISO y Constructor de Formato.
Reglas de entrada y validación
- Detección de longitud: 10=segundos, 13=ms, 16=µs, 19=ns.
- Caracteres permitidos: solo dígitos; rechaza espacios y letras.
- Rango: debe estar dentro de límites seguros de plataforma (revisa 32-bit vs 64-bit; ver FAQ).
- Zona horaria: UTC por defecto; desplazamientos personalizados como
+01:00,-05:30. - DST: la salida usa ISO 8601 con desplazamiento; UTC evita sorpresas de DST.
Fragmentos de código
JavaScript / Node.js
JAVASCRIPT1const detectarPrecision = (raw) => { 2 const len = raw.length; 3 if (len === 10) return { value: Number(raw) * 1000, unit: "ms" }; 4 if (len === 13) return { value: Number(raw), unit: "ms" }; 5 if (len === 16) return { value: Number(raw) / 1000, unit: "ms" }; // µs → ms 6 if (len === 19) return { value: Number(raw) / 1_000_000, unit: "ms" }; // ns → ms 7 throw new Error("Longitud inválida"); 8}; 9 10const aIso = (raw, tz = "UTC") => { 11 const { value } = detectarPrecision(raw); 12 return new Date(value).toISOString(); // Compatible RFC 3339 13}; 14 15console.log(aIso("1704067200")); // 10 dígitos -> segundos 16console.log(aIso("1704067200000")); // 13 dígitos -> milisegundos
Python
PYTHON1from datetime import datetime, timezone, timedelta 2 3def a_iso(raw: str, offset_minutos: int = 0) -> str: 4 longitud = len(raw) 5 if longitud == 10: 6 ts = int(raw) 7 elif longitud == 13: 8 ts = int(raw) / 1000 9 elif longitud == 16: 10 ts = int(raw) / 1_000_000 11 elif longitud == 19: 12 ts = int(raw) / 1_000_000_000 13 else: 14 raise ValueError("Longitud inválida") 15 16 tz = timezone(timedelta(minutes=offset_minutos)) 17 return datetime.fromtimestamp(ts, tz=tz).isoformat() 18 19print(a_iso("1704067200", 0)) # UTC 20print(a_iso("1704067200000", 60)) # UTC+01:00
Go
GO1package main 2 3import ( 4 "fmt" 5 "strconv" 6 "time" 7) 8 9func parseEpoch(raw string) (time.Time, error) { 10 switch len(raw) { 11 case 10: 12 sec, _ := strconv.ParseInt(raw, 10, 64) 13 return time.Unix(sec, 0).UTC(), nil 14 case 13: 15 ms, _ := strconv.ParseInt(raw, 10, 64) 16 return time.Unix(0, ms*int64(time.Millisecond)).UTC(), nil 17 case 16: 18 us, _ := strconv.ParseInt(raw, 10, 64) 19 return time.Unix(0, us*int64(time.Microsecond)).UTC(), nil 20 case 19: 21 ns, _ := strconv.ParseInt(raw, 10, 64) 22 return time.Unix(0, ns).UTC(), nil 23 } 24 return time.Time{}, fmt.Errorf("longitud inválida") 25} 26 27func main() { 28 t, _ := parseEpoch("1704067200") 29 fmt.Println(t.Format(time.RFC3339)) // 2024-01-01T00:00:00Z 30}
FAQ
- ¿Qué pasa si no conozco la precisión? Cuenta los dígitos: 10=s, 13=ms, 16=µs, 19=ns.
- ¿Debería siempre usar UTC? Sí para almacenamiento; convierte a hora local solo para mostrar.
- ¿Esto maneja años bisiestos y DST? Sí, las bibliotecas de fecha lo manejan automáticamente.