Documentación de la API
Integra el reloj de Hora Mundo en tu sitio web
Endpoints de la API
Obtener Hora Mundo
GET
/api/index.php?endpoint=time
Retorna la Hora Mundo actual del servidor.
Respuesta:
{
"hora_mundo_time": "14:30:45",
"hora_mundo_date": "2024-01-15",
"unix_timestamp": 1705329045,
"timezone": "Hora Mundo"
}
Listar Ciudades
GET
/api/index.php?endpoint=cities
Retorna lista de ciudades con sus zonas horarias.
Respuesta:
{
"cities": [
{
"name": "New York",
"country": "USA",
"timezone": "America/New_York",
"offset": "HM-5"
},
...
]
}
Convertir Tiempo
GET
/api/index.php?endpoint=convert&timezone=X&time=HH:MM&direction=to_hora_mundo
Convierte tiempo entre Hora Mundo y zona horaria local.
| Parámetro | Tipo | Descripción |
|---|---|---|
timezone |
string | Zona horaria (ej: America/New_York) |
time |
string | Hora a convertir (formato HH:MM) |
direction |
string | to_hora_mundo o from_hora_mundo |
Ejemplos de Integración
JavaScript
// Usando fetch (navegador o Node.js)
async function getHoraMundoTime() {
const response = await fetch(
'https://www.horamundo.com/api/index.php?endpoint=time'
);
const data = await response.json();
console.log(`Hora Mundo: ${data.hora_mundo_time}`);
return data;
}
// Reloj en tiempo real (cálculo local, más preciso)
function startHoraMundoClock(elementId) {
const update = () => {
const now = new Date();
const h = String(now.getUTCHours()).padStart(2, '0');
const m = String(now.getUTCMinutes()).padStart(2, '0');
const s = String(now.getUTCSeconds()).padStart(2, '0');
document.getElementById(elementId).textContent = `${h}:${m}:${s}`;
};
update();
setInterval(update, 1000);
}
Python
import requests
from datetime import datetime, timezone
# Usando la API
def get_hora_mundo_time():
response = requests.get(
'https://www.horamundo.com/api/index.php',
params={'endpoint': 'time'}
)
data = response.json()
return data['hora_mundo_time']
# Cálculo local (más preciso)
def get_hora_mundo():
now = datetime.now(timezone.utc)
return now.strftime('%H:%M:%S')
print(f"Hora Mundo: {get_hora_mundo()}")
PHP
<?php
// Usando la API
function getHoraMundoTime() {
$url = 'https://www.horamundo.com/api/index.php?endpoint=time';
$response = file_get_contents($url);
$data = json_decode($response, true);
return $data['hora_mundo_time'];
}
// Cálculo local
function getHoraMundoLocal() {
return gmdate('H:i:s');
}
echo "Hora Mundo: " . getHoraMundoLocal();
?>
cURL
# Obtener Hora Mundo
curl -X GET "https://www.horamundo.com/api/index.php?endpoint=time"
# Obtener lista de ciudades
curl -X GET "https://www.horamundo.com/api/index.php?endpoint=cities"
# Convertir hora local a Hora Mundo
curl -X GET "https://www.horamundo.com/api/index.php?endpoint=convert&timezone=America/New_York&time=09:00&direction=to_hora_mundo"
Widget Embebible
Agrega este widget listo para usar en tu sitio:
HTML
<div id="hora-mundo-widget" style="
background: linear-gradient(135deg, #1a1a2e, #16213e);
border-radius: 16px;
padding: 20px;
text-align: center;
font-family: system-ui, sans-serif;
width: fit-content;
">
<div style="color: #888; font-size: 11px; letter-spacing: 1px;">
HORA MUNDO
</div>
<div id="hm-time" style="
color: #fff;
font-size: 42px;
font-weight: bold;
margin: 8px 0;
">--:--</div>
<div style="
background: rgba(74, 144, 217, 0.2);
color: #4a90d9;
padding: 4px 12px;
border-radius: 4px;
font-size: 12px;
font-weight: bold;
display: inline-block;
">Hora Mundo</div>
</div>
<script>
setInterval(() => {
const d = new Date();
const h = String(d.getUTCHours()).padStart(2,'0');
const m = String(d.getUTCMinutes()).padStart(2,'0');
document.getElementById('hm-time').textContent = h+':'+m;
}, 1000);
</script>
Notas Importantes
- CORS: La API permite solicitudes desde cualquier origen (CORS habilitado).
- Rate Limiting: No hay límite de solicitudes actualmente.
- Precisión: Para relojes en tiempo real, usa cálculo local (JavaScript Date) en lugar de llamadas repetidas a la API.
- Cache: Los endpoints pueden tener caché de hasta 1 segundo.