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

              
                // Now
const now = new Date();
// Get the hour from `now`
const hour = now.getHours();
// Add 7 days to `now`
const weekAdd = new Date();
weekAdd.setDate(now.getDate() + 7);
// `now` formatted like "Monday, November 23, 5pm"
const dateFormatted = "No easy built in way to do this"
// Using Intl.DateTimeFormat to show the current time and date on Lord Howe Island
const dateTimeLocale = new Intl.DateTimeFormat("en-en", {
  dateStyle: "full",
  timeStyle: "long",
  timeZone: "Australia/Lord_Howe"
}).format(now);
// Parsing two different strings as dates
// Note they are different
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#Timestamp_string
// and https://stackoverflow.com/a/20463521
const dateTimeParsing1 = new Date(Date.parse("Jul 8, 2005"));
const dateTimeParsing2 = new Date(Date.parse("2005-07-08"));


document.getElementById("package-link").innerHTML = "native JavaScript Date and Intl objects"
document.getElementById("package-link").href = "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date"
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