Last active
May 25, 2017 00:40
-
-
Save leodutra/19faa09a46dd168d753d6abdf92dd33e to your computer and use it in GitHub Desktop.
Date functions for pt-br systems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isDiaMesAno(dd_mm_yyyy) { | |
var matches = String(dd_mm_yyyy).trim().match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/) | |
var date = matches && new Date(matches[3], matches[2] - 1, matches[1]); | |
return !!(date && (date.getMonth() + 1) == matches[2]); | |
} | |
function isHoraMinuto(hh_mm) { | |
var matches = String(hh_mm).trim().match(/^(\d{2}):(\d{2})$/) | |
var date = matches && new Date(2017, 0, 1, matches[1], matches[2]); | |
return !!(date && date.getHours() == matches[1]); | |
} | |
function diaMesAnoAtual() { | |
var date = new Date(); | |
var dd = date.getDate(); | |
var mm = date.getMonth() + 1; | |
var aaaa = date.getFullYear(); | |
return (dd < 2 ? '0' + dd : dd) + '/' + (mm < 2 ? '0' + mm : mm) + '/' + aaaa; | |
} | |
function horaMinutoAtual() { | |
var date = new Date(); | |
var hh = date.getHours(); | |
var mm = date.getMinutes(); | |
return (hh < 2 ? '0' + hh : hh) + ':' + (mm < 2 ? '0' + mm : mm); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment