Skip to content

Instantly share code, notes, and snippets.

@jvinceso
Created August 6, 2016 02:21
Show Gist options
  • Save jvinceso/764e4ffb098e67bc8a7313961c769c69 to your computer and use it in GitHub Desktop.
Save jvinceso/764e4ffb098e67bc8a7313961c769c69 to your computer and use it in GitHub Desktop.
Add Month dd/mm/YYYY from string to Date
var fechaString = '25/08/2016';
function parsearFecha(stringDate){
var arregloFEchas = stringDate.split("/");
var fecha = new Date(arregloFEchas[2] + '/' + arregloFEchas[1] + '/' + arregloFEchas[0]);
var dia = fecha.getDate();
var mes = fecha.getMonth() + 1;
var anio = fecha.getFullYear();
var tiempo = 30;
var addTime = tiempo * 86400; //Tiempo en segundos
fecha.setSeconds(addTime); //Añado el tiempo
var monthNames = [
"01", "02", "03",
"04", "05", "06", "07",
"08", "09", "10",
"11", "12"
];
var dayNames = [
"00", "01", "02", "03",
"04", "05", "06", "07",
"08", "09", "10",
"11", "12", "13", "14", "15",
"16", "17", "18", "19", "20",
"21", "22", "23", "24", "25",
"26", "27", "28", "29", "30", "31"
];
var ms = fecha.getFullYear() + "/" + monthNames[(fecha.getMonth())] + "/" + dayNames[fecha.getDate()];
return ms;
}
console.log( parsearFecha('25/08/2016') )
//Result==> 2016/09/24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment