Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>datetime with <a href="" target="new" id="package-link"></a></h1>
<div>
  <h2>Your time = <code>now</code></h2>
  <span id="today"> </span>
</div>

<div>
  <h2>Get the hour from <code>now</code></h2>
  <span id="today-hour"> </span>
</div>

<div>
  <h2>Add 7 days to <code>now</code></h2>
  <span id="week-add"> </span>
</div>

<div>
  <h2><code>now</code> formatted like "Monday, November 23, 5pm"</h2>
  <span id="date-formatted"></span>
</div>

<div>
  <h2>Date and time on Lord Howe Island</h2>
  <span id="date-time-locale"></span>
</div>

<div>
  <h2>Parsing <code>Jul 8, 2005</code></h2>
  <span id="date-time-parsing-1"></span>
</div>

<div>
  <h2>Parsing <code>2005-07-08</code></h2>
  <span id="date-time-parsing-2"></span>
</div>

              
            
!

CSS

              
                
              
            
!

JS

              
                import { format, add, getHours, parse } from "https://cdn.skypack.dev/date-fns@2.16.1";

// Now
// Uses the native JavaScript date
const now = new Date()
// Get the hour from today
const hour = getHours(now)
// Add 7 days to now
const weekAdd = add(now, {days: 7})
// Now formatted like "Monday, November 23, 5pm"
const dateFormatted = format(now, "EEEE',' MMMM d',' ha")

// Date and time on Lord Howe Island
// We need date-fns-tz for this
import { zonedTimeToUtc, utcToZonedTime } from "https://cdn.skypack.dev/date-fns-tz"
const zonedDate = utcToZonedTime(now,  "Australia/Lord_Howe")
const pattern = "d.M.yyyy HH:mm:ss.SSS \'GMT\' XXX (z)"
const dateTimeLocale = format(zonedDate, pattern, { timeZone: "Australia/Lord_Howe" })

// Parsing
const dateTimeParsing1 = parse("Jul 8, 2005", "MMM d, y", new Date())
const dateTimeParsing2 = parse("2005-07-08", "y-MM-dd", new Date())

document.getElementById("package-link").innerHTML = "date-fns"
document.getElementById("package-link").href = "https://www.skypack.dev/view/date-fns"
document.getElementById('today').innerHTML = now
document.getElementById('today-hour').innerHTML = hour
document.getElementById('week-add').innerHTML = weekAdd
document.getElementById('date-formatted').innerHTML = dateFormatted
document.getElementById('date-time-locale').innerHTML = dateTimeLocale
document.getElementById("date-time-parsing-1").innerHTML = dateTimeParsing1;
document.getElementById("date-time-parsing-2").innerHTML = dateTimeParsing2;

              
            
!
999px

Console