-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdates.html
More file actions
153 lines (138 loc) · 7.21 KB
/
Copy pathdates.html
File metadata and controls
153 lines (138 loc) · 7.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Date Tools | tools.eliana.lol</title>
<link rel="stylesheet" href="../global.css" />
<link rel="icon" type="image/x-icon" href="../favicon.svg" />
<style>
.tool-layout { display: flex; flex-direction: column; gap: 24px; }
.action-bar { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
label { display: block; font-size: 0.7rem; text-transform: uppercase; font-weight: bold; color: var(--puny); margin-bottom: 5px; }
.card { border: 1px solid var(--puny); padding: 14px; }
.card h2 { font-size: 0.9rem; text-transform: uppercase; margin: 0 0 12px 0; padding-bottom: 6px; border-bottom: 1px solid var(--puny); }
.result { font-size: 0.9rem; margin-top: 8px; min-height: 1.4rem; font-weight: bold; }
.result.puny { font-weight: normal; }
select { background: var(--bg); color: var(--text); border: 1px solid var(--puny); font-family: monospace; padding: 4px 8px; }
input[type=date], input[type=datetime-local] { background: var(--bg); color: var(--text); border: 1px solid var(--puny); font-family: monospace; padding: 6px 8px; }
.formats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; font-size: 0.8rem; }
.formats span { color: var(--puny); }
.formats strong { font-family: monospace; }
#live-clock { font-size: 1.8rem; font-weight: bold; text-align: center; padding: 16px; border: 1px solid var(--puny); letter-spacing: 2px; }
</style>
</head>
<body>
<nav>
<div class="left"><a href="../index.html">home</a> | <a href="../extra.html">extra</a> | <a href="../credits.html">credits</a> | <a href="../changelog.html">logs</a></div>
<div class="right"><button id="theme-toggle">[theme]</button> | <a href="https://eliana.lol">site</a></div>
</nav>
<main>
<h1>Date Tools</h1>
<p class="puny">Format dates, calculate differences, convert timezones. Powered by Day.js.</p>
<div class="tool-layout">
<div id="live-clock"></div>
<div class="card">
<h2>Format a date</h2>
<label>Date</label>
<input type="datetime-local" id="fmt-date" />
<label style="margin-top:10px">Format string</label>
<input type="text" id="fmt-str" value="MMMM D, YYYY [at] h:mm A" />
<div class="result" id="fmt-result"></div>
<div class="formats" style="margin-top:10px">
<span>YYYY</span><strong>2026</strong>
<span>MM</span><strong>06</strong>
<span>DD</span><strong>14</strong>
<span>dddd</span><strong>Sunday</strong>
<span>h:mm A</span><strong>2:30 PM</strong>
<span>HH:mm</span><strong>14:30</strong>
<span>x</span><strong>unix ms</strong>
<span>Q</span><strong>quarter</strong>
</div>
<div class="action-bar"><button onclick="formatDate()">Format</button></div>
</div>
<div class="card">
<h2>Date difference</h2>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:12px">
<div><label>From</label><input type="date" id="diff-from" /></div>
<div><label>To</label><input type="date" id="diff-to" /></div>
</div>
<div class="action-bar"><button onclick="calcDiff()">Calculate</button></div>
<div class="result" id="diff-result"></div>
</div>
<div class="card">
<h2>Relative time</h2>
<label>Date</label>
<input type="datetime-local" id="rel-date" />
<div class="action-bar"><button onclick="calcRelative()">From now</button></div>
<div class="result" id="rel-result"></div>
</div>
<div class="card">
<h2>Unix timestamp</h2>
<label>Timestamp (seconds or ms)</label>
<input type="text" id="unix-in" placeholder="e.g. 1700000000" />
<div class="action-bar">
<button onclick="fromUnix()">Convert to date</button>
<button onclick="toUnix()">Now → Unix</button>
</div>
<div class="result" id="unix-result"></div>
</div>
</div>
</main>
<footer style="margin-top: 4rem; text-align: center" class="puny">© 2026 eliana.lol • <a href="../credits.html">credits</a></footer>
<script src="https://cdn.jsdelivr.net/npm/dayjs@1.11.10/dayjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dayjs@1.11.10/plugin/relativeTime.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dayjs@1.11.10/plugin/duration.js"></script>
<script>
const htmlEl = document.documentElement;
const toggle = document.getElementById('theme-toggle');
const saved = localStorage.getItem('theme') || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
htmlEl.setAttribute('data-theme', saved);
if (toggle) toggle.innerText = saved === 'dark' ? '[light]' : '[dark]';
if (toggle) toggle.onclick = () => { const now = htmlEl.getAttribute('data-theme'); const next = now === 'dark' ? 'light' : 'dark'; htmlEl.setAttribute('data-theme', next); localStorage.setItem('theme', next); toggle.innerText = next === 'dark' ? '[light]' : '[dark]'; };
dayjs.extend(window.dayjs_plugin_relativeTime);
dayjs.extend(window.dayjs_plugin_duration);
// Live clock
function updateClock() { document.getElementById('live-clock').textContent = dayjs().format('ddd, MMM D YYYY · HH:mm:ss'); }
updateClock(); setInterval(updateClock, 1000);
// Pre-fill inputs with now
const now = dayjs().format('YYYY-MM-DDTHH:mm');
const today = dayjs().format('YYYY-MM-DD');
document.getElementById('fmt-date').value = now;
document.getElementById('rel-date').value = now;
document.getElementById('diff-from').value = today;
document.getElementById('diff-to').value = dayjs().add(30, 'day').format('YYYY-MM-DD');
function formatDate() {
const d = document.getElementById('fmt-date').value;
const fmt = document.getElementById('fmt-str').value;
if (!d) return;
document.getElementById('fmt-result').textContent = dayjs(d).format(fmt);
}
function calcDiff() {
const from = dayjs(document.getElementById('diff-from').value);
const to = dayjs(document.getElementById('diff-to').value);
const days = to.diff(from, 'day');
const weeks = to.diff(from, 'week');
const months = to.diff(from, 'month');
document.getElementById('diff-result').textContent = `${Math.abs(days)} days · ${Math.abs(weeks)} weeks · ${Math.abs(months)} months ${days < 0 ? '(past)' : ''}`;
}
function calcRelative() {
const d = document.getElementById('rel-date').value;
if (!d) return;
document.getElementById('rel-result').textContent = dayjs(d).fromNow();
}
function fromUnix() {
const ts = parseInt(document.getElementById('unix-in').value.trim());
if (isNaN(ts)) return;
const ms = ts > 1e10 ? ts : ts * 1000;
document.getElementById('unix-result').textContent = dayjs(ms).format('MMMM D, YYYY HH:mm:ss');
}
function toUnix() {
const ts = dayjs().unix();
document.getElementById('unix-in').value = ts;
document.getElementById('unix-result').textContent = `Now = ${ts} (seconds) · ${dayjs().valueOf()} (ms)`;
}
formatDate(); calcDiff();
</script>
</body>
</html>