Skip to content

Instantly share code, notes, and snippets.

@goedecke
Created February 24, 2017 19:52
Show Gist options
  • Save goedecke/046df9012d3c6f3afc07cdbb6766ea32 to your computer and use it in GitHub Desktop.
Save goedecke/046df9012d3c6f3afc07cdbb6766ea32 to your computer and use it in GitHub Desktop.
Fecha menos o mas Local para ajustar a GMT
function fechaMexCRM(fecha, tipo){
var tc = new Date().toString().split("GMT")[1].split(" ")[0].replace(/0/g,"");
if (tipo === 'get'){
var tc = tc*1;
} else {
var tc = tc*-1;
}
if (tipo === 'X'){
fechahora = fecha.split(' ');
} else {
fechahora = fecha.split('T');
}
fecha = fechahora[0];
fecha = fecha.replace( /(\d{4})-(\d{2})-(\d{2})/, "$2/$3/$1");
horacmicros = fechahora[1].split(':');
hora = horacmicros[0]+':'+horacmicros[1];
fecha = fecha+" "+hora;
var fecha = new Date(fecha);
var myDate = new Date(fecha.getTime() + (tc * 3600 * 1000));
var mes = myDate.getMonth() + 1;
var ano = (myDate.getFullYear()>9 ? '' : '0')+myDate.getFullYear();
var mes = (mes>9 ? '' : '0')+mes;
var dia = (myDate.getDate()>9 ? '' : '0')+myDate.getDate();
var hora = (myDate.getHours()>9 ? '' : '0')+myDate.getHours();
var minuto = (myDate.getMinutes()>9 ? '' : '0')+myDate.getMinutes();
var segundo = "00";
return ano+"-"+mes+"-"+dia+" "+hora+":"+minuto+":"+segundo;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment