🤖 Ai回答: To use Day.js via a CDN (Content Delivery Network), you can include it in your HTML file using the following script tag:
html
<script src=https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js</script
This will load the latest version of Day.js from the jsDelivr CDN、If you want to use a specific version, you can specify it in the URL、For example, to use version 1.11.7:
html
<script src=https://cdn.jsdelivr.net/npm/dayjs@1.11.7/dayjs.min.js</script
If you need to use any Day.js plugins, you'll need to include them separately、For example, to include the `relativeTime` plugin:
html
<script src=https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js</script
<script src=https://cdn.jsdelivr.net/npm/dayjs@1/plugin/relativeTime.js</script
Then, in your JavaScript code, you can use Day.js like this:
javascript
dayjs.extend(window.dayjs_plugin_relativeTime); // Extend with relativeTime plugin
console.log(dayjs().fromNow()); // Example usage
Remember that when using Day.js via a CDN, it's attached to the global `dayjs` object, so you don't need to import it in your JavaScript code.