5
Phlisg
7y

Grrrr

I love JS, but I hate browsers.

Universal ES5 way to initialize a date from a input value in "dd.mm.YYYY" format:

var split = input.value.split('.');
var from = {};
from.day = parseInt(split[0]);
from.month = parseInt(split[1])-1;
from.year = parseInt(split[2]);

var myDate = new Date(from.year, from.month, from.day);
// if a timestamp format is needed:
var myDateTimestamp = +new Date(from.year, from.month, from.day);

No, I won't use moment.js or other bloat-braries just for fucking dates.

Comments
  • 0
    @irene hahaha I guess it was answered since the dawn of times - but since I tend to find solutions myself, this is more of a memo :D
Add Comment