JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<h1>DateTime ISO-8601 Extractor</h1>
<small>Pattern like: <mark>1994-11-05T08:15:30-05:00</mark> or <mark>1994-11-05T13:15:30Z</mark> </small><br>
<small>It's not for this pattern: <mark class='orange'>20150930T012823Z</mark> (without punctutu)</small>
<input id='input' onclick="this.select()" oninput="document.getElementById('output').innerHTML=extractAll(this.value)" placeholder="paste ISO 8601 date-time format here" size='40' type="text">
<div id="output" class='res'>
<span class='faded' id='result'>Result</span>
</div>
body {
background: #eee;
text-align: center;
}
body,
input {
font-family: consolas, monaco, menlo, courier, monospace;
box-sizing: border-box;
}
input {
padding: 10px 20px;
margin: 30px auto;
border-radius: 6px;
font-size: 1.2em;
background-color: azure;
display: block;
max-width: 100%;
text-align: center;
}
input:focus {
outline: none;
background-color: #fff;
}
.res {
font-size: 2em;
}
.faded {
color: #bbb;
}
hr {
width: 500px;
max-width: 100%;
border:0;
border-bottom: 1px solid #fff;
background-color: #ccc;
height: 1px;
}
.orange {
background-color: orange;
}
function extractAll(a) {
"use strict";
var buff, date, monthNames, day, month, year, hour, minute, second, plusMinus, tz, output;
if (a.length) {
//By the power of Regular Expression
if (/^\d+-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}(\.\d+)?(([\-\+]\d{2}\:\d{2})|Z)$/.test(a)) {
buff = a.split("T");
date = buff[0].split("-");
day = date[2];
month = date[1];
year = date[0];
buff = buff[1];
buff = buff.split(":");
hour = buff[0];
minute = buff[1];
second = buff[2];
buff = buff.join(":");
if (/\+/.test(buff)) {
plusMinus = "+";
} else if (/-/.test(buff)) {
plusMinus = "-";
} else if (/Z/.test(buff)) {
plusMinus = "Z";
}
buff = buff.split(plusMinus);
tz = plusMinus === "Z"
? ""
: plusMinus + buff[1];
second = second.split(plusMinus)[0];
monthNames = "January,February,March,April,May,June,July,August,September,October,November,December";
monthNames = monthNames.split(",");
output = "Date: <mark>" + monthNames[Number(month) - 1] + " " + day + ", " + year + "</mark>" +
"<br><hr>Time (24h): <mark>" + hour + ":" + minute + ":" + second + "</mark>" +
"<br><hr>Time Zone Designator: <mark>UTC" + tz + "</mark>";
} else {
output = "<code style='color:red'>invalid input</code>";
}
} else {
output = "<span class='faded'>Result</span>";
}
return output;
}
Also see: Tab Triggers