<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<input type="text" id="date1" value="12/12/1975">
<input type="text" id="date2" value="12 Dec 1975">
<button id="btn1">
Press me
</button>
<button id="btn2">
Test Press Me
</button>
<button id="sorting">
Press for sort! watch console
</button>
<button id="fromEpoch">
Fro current unix time to current moment day
</button>
<br>
<input id="quarterDay" type="text" value="23/04/2018">
<button id="quarter">
Press to see quarter information
</button>
JavaScript
$("#btn1").on("click",function() {
var date = $("#date1").val();
var dat2 = $("#date2").val();
console.log("the date is:"+date);
var today = new Date();
var todayMoment = moment();
console.log("todays date is -> "+todayMoment.format("D MMMM YYYY"));
//var day = moment(date);
var day = moment(date,"D/MM/YYYY",true);
console.log(day);
console.log("is the day valid:"+day.isValid());
if(!day.isValid()) {
var invalidAt = day.invalidAt();
console.log("invalidAt:"+invalidAt);
if(invalidAt == 0) console.log("years");
if(invalidAt == 1) console.log("months");
if(invalidAt == 2) console.log("days");
if(invalidAt == 3) console.log("hours");
if(invalidAt == 4) console.log("minutes");
if(invalidAt == 5) console.log("seconds");
if(invalidAt == 6) console.log("milli");
$("#date2").val("Err ");
console.log("the date1 is it using this format? ")
day = moment(date,"D/M/YYYY");
console.log("is day valid?"+day.isValid());
if(day.isValid()) {
var parsedDate = day.format("DD MMM YYYY");
$("#date2").val(parsedDate);
}
}
else {
//are we using different format?
var parsedDate = day.format("D MMM YYYY");
$("#date2").val(parsedDate);
}
});
$("#btn2").on("click",function() {
var date = $("#date1").val();
var obj = processCorrectMoment(date);
console.log(obj);
if(obj.isValid ) {
var parsedDate = obj.moment.format(obj.formatTo);
$("#date2").val(parsedDate);
}
else {
$("#date2").val("Err");
}
});
$("#sorting").on("click",function() {
var arr = [
{expDate:"28 Feb 2028",id:"1"},
{expDate:"15 Dec 2018",id:"2"},
{expDate:"3 Dec 2028",id:"3"},
{expDate:"22 Dec 2016",id:"4"},
{expDate:"21 Dec 2016",id:"5"},
{expDate:"",id:"6"},
{expDate:"5 Jan 2016",id:"7"}
];
var newArr = [];
console.log("this is the current array: ",arr);
console.log("lets convertthem to moment dates");
arr.forEach(function(ele,index) {
var momentDay = moment(ele.expDate,"D MMM YYYY");
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.