Day.js
v1.11.23Tiny date library with a Moment.js compatible API for parsing and formatting dates.
Quick start
Add this tag to your page. Place it just before the closing </body> tag, or in the <head> with the defer attribute.
HTML
<script src="https://jscdns.net/libs/dayjs/1.11.23/dayjs.min.js"
integrity="sha384-1Ft4/JTNbt7S/44V0himpcjx+YfQ1a6W6SYBJMr94ba6jwZhWoWoLaZsMmtJILgq" crossorigin="anonymous"></script>Files
| File | Size | Copy |
|---|---|---|
| dayjs.min.jsScript | 7.0 KB |
Usage
Complete example
A minimal page that loads Day.js and uses it. Copy it into a file and open it in your browser.
example.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<p id="today"></p>
<script src="https://jscdns.net/libs/dayjs/1.11.23/dayjs.min.js"
integrity="sha384-1Ft4/JTNbt7S/44V0himpcjx+YfQ1a6W6SYBJMr94ba6jwZhWoWoLaZsMmtJILgq" crossorigin="anonymous"></script>
<script>
const now = dayjs();
document.querySelector('#today').textContent =
now.format('dddd D MMMM YYYY, HH:mm');
console.log(now.add(7, 'day').format('YYYY-MM-DD'));
</script>
</body>
</html>Good to know. A good lightweight replacement for Moment.js, which is in maintenance mode.