Javascript date

Javascript date, some handy functions

For working with dates in javascript you will have to start with a Data object. A date object is has a constructor which wants a string or strings which will be parsed as a date. Sometimes you work with date-string which this object cannot parse as a valid string. F.I if you work with dutch date strings of Json strings.

In this case you will need some basic functions, so here they are:

function parseDutchDate(dutchDate) {
    var dateParts = dutchDate.split("-");
    var date = new Date(dateParts[2], (dateParts[1] - 1), dateParts[0]);
    return date;
} 
function getDateFromJson(jsonDate)
{
    if (jsonDate == null) return "";
    var subStr = jsonDate.substr(6);
    var intDate = parseInt(subStr);
    var jDate = new Date(intDate);

    var yyyy =  jDate.getFullYear();
    var mm = jDate.getMonth() < 9 ? "0" + (jDate.getMonth() + 1) : (jDate.getMonth() + 1);
    var dd = jDate.getDate() < 10 ? "0" + jDate.getDate() : jDate.getDate();
    var hh = jDate.getHours() < 10 ? "0" + jDate.getHours() : jDate.getHours();
    var min = jDate.getMinutes() < 10 ? "0" + jDate.getMinutes() : jDate.getMinutes();    
    return "".concat(dd).concat('-').concat(mm).concat('-').concat(yyyy).concat(' ').concat(hh).concat(':').concat(min);

} 
function isDate(date) {
    var parsed = false;
    try {
        var d = Date.parse(date);
        if (!isNaN(d)) {
            parsed = true;
        }
    } catch (e)  {
    }
    return parsed;
} 
Date.prototype.getMonthName = function () {
    var m = ['Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul',
    'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    return m[this.getMonth()];
} 

{{opmerking.Naam}}:

{{opmerking.OpmerkingText}}

            

Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!