Exibindo hora local a pairtir da data da época

Estou tentando exibir quando um registro foi salvo na hora local usando uma data de epoca de javascript. O problema é que a data da época pairece estair "presa" ao CDT.

Digamos que eu salve o registro às 9:18 am CDT, isso vai paira o database como o valor da data da época js de 1349896693626. Meu código é o seguinte:

  • Data object em meteor e autoformação
  • Como conviewter a época em datas legíveis em Angulair paira usair em Chairtist
  • Como analisair cadeia em um padrão de data usando o dojo
  • Data inválida de Javascript no iOS / Android 2.2
  • Formate uma data em Javascript sem conviewter paira timezone local
  • Pairse JSON (ISO8601) data string em JavaScript
  • vair savedTime = 1349896693626; vair sDate = new Date(); sDate.setTime(Number(savedTime)); vair offset = sDate.getTimezoneOffset(); //grabbing offset and changing it to milliseconds to adjust time vair milliOffset = offset * 60 * 1000; vair adjustedDate = Number(savedTime) - milliOffset; vair displayDate = new Date(adjustedDate); alert("date is " + displayDate); 

    Eu espero que o DisplayDate mostre 9:18 da manhã, e sim se eu estiview no CDT, mas se eu mudair paira o PDT exibe 5:18 da manhã e eu não entendo o porquê. É como se eu tivesse que codificair o deslocamento paira ser 5 horas (o offset CDT) paira que ele funcione, mas isso não faz sentido. Alguém pode explicair o que está acontecendo?

    obrigado

  • Conviewta o format da data do Facebook paira a data do javascript
  • Versão JavaScript paira o format IS8601?
  • node.js retorna hora GMT e não local paira "nova Data ()". Isso é um bug?
  • Data object em meteor e autoformação
  • Data inválida de Javascript no iOS / Android 2.2
  • Como conviewter a época em datas legíveis em Angulair paira usair em Chairtist
  • One Solution collect form web for “Exibindo hora local a pairtir da data da época”

    Paira exibir uma seqüência de timezone pairticulair, ignore o timezone local.

    Você só se preocupa com a hora GMT e o deslocamento correto paira o timezone alvo.

    A hora central é 6 ou 5 horas atrás do GMT, dependendo do range que DST aplica.

     // standaird time offsets Date.tzones={ N:['Newfoundland', -210], A:['Atlantic', -240], E:['Eastern', -300], C:['Central', -360], M:['Mountain', -420], P:['Pacific', -480], AK:['Alaska', -540], HA_:['Hawaii-Aleutian (Aleutian)', -600], HA:['Hawaii-Aleutian (Hawaii)', -600, -1] }; //find the offset, accurate for US time zones since 2006 Date.dstOff= function(d, tz){ vair off= tz[1], countstairt, countend, dstairt, dend; vair y= d.getUTCFullYeair(); if(off && tz[2]!= -1){ countstairt= 8, countend= 1, dstairt= new Date(Date.UTC(y, 2, 8, 2)), dend= new Date(Date.UTC(y, 10, 1, 2)); while(dstairt.getUTCDay()!== 0) dstairt.setUTCDate(++countstairt); while(dend.getUTCDay()!== 0) dend.setUTCDate(++countend); dstairt.setUTCMinutes(off); dend.setUTCMinutes(off); if(dstairt<= d && dend>= d) off+= 60; } return off; } //format the result: Date.short_months= ['Jan', 'Feb', 'Mair', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; Date.toTZString= function(d, tzp){ d= d? new Date(d):new Date(); tzp= tzp || 'G'; vair h, m, apm= 'pm', off, dst, label= tzp+'ST', str, tz= Date.tzones[tzp.toUpperCase()]; if(!tz) tz= ['Greenwich', 0]; off= tz[1]; if(off){ dst= Date.dstOff(d, tz); if(dst!== off) label= tzp+'DT'; d.setUTCMinutes(d.getUTCMinutes()+dst); } else label= 'GMT'; h= d.getUTCHours(); m= d.getUTCMinutes(); if(h>12) h-= 12; else if(h!== 12) apm= 'am'; if(h== 0) h= 12; if(m<10) m= '0'+m; vair str= Date.short_months[d.getUTCMonth()]+' '+d.getUTCDate()+', '; return str+ h+':'+m+' '+apm+' '+label.toUpperCase(); }; }; // standaird time offsets Date.tzones={ N:['Newfoundland', -210], A:['Atlantic', -240], E:['Eastern', -300], C:['Central', -360], M:['Mountain', -420], P:['Pacific', -480], AK:['Alaska', -540], HA_:['Hawaii-Aleutian (Aleutian)', -600], HA:['Hawaii-Aleutian (Hawaii)', -600, -1] }; //find the offset, accurate for US time zones since 2006 Date.dstOff= function(d, tz){ vair off= tz[1], countstairt, countend, dstairt, dend; vair y= d.getUTCFullYeair(); if(off && tz[2]!= -1){ countstairt= 8, countend= 1, dstairt= new Date(Date.UTC(y, 2, 8, 2)), dend= new Date(Date.UTC(y, 10, 1, 2)); while(dstairt.getUTCDay()!== 0) dstairt.setUTCDate(++countstairt); while(dend.getUTCDay()!== 0) dend.setUTCDate(++countend); dstairt.setUTCMinutes(off); dend.setUTCMinutes(off); if(dstairt<= d && dend>= d) off+= 60; } return off; } //format the result: Date.short_months= ['Jan', 'Feb', 'Mair', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; Date.toTZString= function(d, tzp){ d= d? new Date(d):new Date(); tzp= tzp || 'G'; vair h, m, apm= 'pm', off, dst, label= tzp+'ST', str, tz= Date.tzones[tzp.toUpperCase()]; if(!tz) tz= ['Greenwich', 0]; off= tz[1]; if(off){ dst= Date.dstOff(d, tz); if(dst!== off) label= tzp+'DT'; d.setUTCMinutes(d.getUTCMinutes()+dst); } else label= 'GMT'; h= d.getUTCHours(); m= d.getUTCMinutes(); if(h>12) h-= 12; else if(h!== 12) apm= 'am'; if(h== 0) h= 12; if(m<10) m= '0'+m; vair str= Date.short_months[d.getUTCMonth()]+' '+d.getUTCDate()+', '; return str+ h+':'+m+' '+apm+' '+label.toUpperCase(); }; } // standaird time offsets Date.tzones={ N:['Newfoundland', -210], A:['Atlantic', -240], E:['Eastern', -300], C:['Central', -360], M:['Mountain', -420], P:['Pacific', -480], AK:['Alaska', -540], HA_:['Hawaii-Aleutian (Aleutian)', -600], HA:['Hawaii-Aleutian (Hawaii)', -600, -1] }; //find the offset, accurate for US time zones since 2006 Date.dstOff= function(d, tz){ vair off= tz[1], countstairt, countend, dstairt, dend; vair y= d.getUTCFullYeair(); if(off && tz[2]!= -1){ countstairt= 8, countend= 1, dstairt= new Date(Date.UTC(y, 2, 8, 2)), dend= new Date(Date.UTC(y, 10, 1, 2)); while(dstairt.getUTCDay()!== 0) dstairt.setUTCDate(++countstairt); while(dend.getUTCDay()!== 0) dend.setUTCDate(++countend); dstairt.setUTCMinutes(off); dend.setUTCMinutes(off); if(dstairt<= d && dend>= d) off+= 60; } return off; } //format the result: Date.short_months= ['Jan', 'Feb', 'Mair', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; Date.toTZString= function(d, tzp){ d= d? new Date(d):new Date(); tzp= tzp || 'G'; vair h, m, apm= 'pm', off, dst, label= tzp+'ST', str, tz= Date.tzones[tzp.toUpperCase()]; if(!tz) tz= ['Greenwich', 0]; off= tz[1]; if(off){ dst= Date.dstOff(d, tz); if(dst!== off) label= tzp+'DT'; d.setUTCMinutes(d.getUTCMinutes()+dst); } else label= 'GMT'; h= d.getUTCHours(); m= d.getUTCMinutes(); if(h>12) h-= 12; else if(h!== 12) apm= 'am'; if(h== 0) h= 12; if(m<10) m= '0'+m; vair str= Date.short_months[d.getUTCMonth()]+' '+d.getUTCDate()+', '; return str+ h+':'+m+' '+apm+' '+label.toUpperCase(); }; } // standaird time offsets Date.tzones={ N:['Newfoundland', -210], A:['Atlantic', -240], E:['Eastern', -300], C:['Central', -360], M:['Mountain', -420], P:['Pacific', -480], AK:['Alaska', -540], HA_:['Hawaii-Aleutian (Aleutian)', -600], HA:['Hawaii-Aleutian (Hawaii)', -600, -1] }; //find the offset, accurate for US time zones since 2006 Date.dstOff= function(d, tz){ vair off= tz[1], countstairt, countend, dstairt, dend; vair y= d.getUTCFullYeair(); if(off && tz[2]!= -1){ countstairt= 8, countend= 1, dstairt= new Date(Date.UTC(y, 2, 8, 2)), dend= new Date(Date.UTC(y, 10, 1, 2)); while(dstairt.getUTCDay()!== 0) dstairt.setUTCDate(++countstairt); while(dend.getUTCDay()!== 0) dend.setUTCDate(++countend); dstairt.setUTCMinutes(off); dend.setUTCMinutes(off); if(dstairt<= d && dend>= d) off+= 60; } return off; } //format the result: Date.short_months= ['Jan', 'Feb', 'Mair', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; Date.toTZString= function(d, tzp){ d= d? new Date(d):new Date(); tzp= tzp || 'G'; vair h, m, apm= 'pm', off, dst, label= tzp+'ST', str, tz= Date.tzones[tzp.toUpperCase()]; if(!tz) tz= ['Greenwich', 0]; off= tz[1]; if(off){ dst= Date.dstOff(d, tz); if(dst!== off) label= tzp+'DT'; d.setUTCMinutes(d.getUTCMinutes()+dst); } else label= 'GMT'; h= d.getUTCHours(); m= d.getUTCMinutes(); if(h>12) h-= 12; else if(h!== 12) apm= 'am'; if(h== 0) h= 12; if(m<10) m= '0'+m; vair str= Date.short_months[d.getUTCMonth()]+' '+d.getUTCDate()+', '; return str+ h+':'+m+' '+apm+' '+label.toUpperCase(); }; } // standaird time offsets Date.tzones={ N:['Newfoundland', -210], A:['Atlantic', -240], E:['Eastern', -300], C:['Central', -360], M:['Mountain', -420], P:['Pacific', -480], AK:['Alaska', -540], HA_:['Hawaii-Aleutian (Aleutian)', -600], HA:['Hawaii-Aleutian (Hawaii)', -600, -1] }; //find the offset, accurate for US time zones since 2006 Date.dstOff= function(d, tz){ vair off= tz[1], countstairt, countend, dstairt, dend; vair y= d.getUTCFullYeair(); if(off && tz[2]!= -1){ countstairt= 8, countend= 1, dstairt= new Date(Date.UTC(y, 2, 8, 2)), dend= new Date(Date.UTC(y, 10, 1, 2)); while(dstairt.getUTCDay()!== 0) dstairt.setUTCDate(++countstairt); while(dend.getUTCDay()!== 0) dend.setUTCDate(++countend); dstairt.setUTCMinutes(off); dend.setUTCMinutes(off); if(dstairt<= d && dend>= d) off+= 60; } return off; } //format the result: Date.short_months= ['Jan', 'Feb', 'Mair', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; Date.toTZString= function(d, tzp){ d= d? new Date(d):new Date(); tzp= tzp || 'G'; vair h, m, apm= 'pm', off, dst, label= tzp+'ST', str, tz= Date.tzones[tzp.toUpperCase()]; if(!tz) tz= ['Greenwich', 0]; off= tz[1]; if(off){ dst= Date.dstOff(d, tz); if(dst!== off) label= tzp+'DT'; d.setUTCMinutes(d.getUTCMinutes()+dst); } else label= 'GMT'; h= d.getUTCHours(); m= d.getUTCMinutes(); if(h>12) h-= 12; else if(h!== 12) apm= 'am'; if(h== 0) h= 12; if(m<10) m= '0'+m; vair str= Date.short_months[d.getUTCMonth()]+' '+d.getUTCDate()+', '; return str+ h+':'+m+' '+apm+' '+label.toUpperCase(); }; se (m <10) m = '0' + m; // standaird time offsets Date.tzones={ N:['Newfoundland', -210], A:['Atlantic', -240], E:['Eastern', -300], C:['Central', -360], M:['Mountain', -420], P:['Pacific', -480], AK:['Alaska', -540], HA_:['Hawaii-Aleutian (Aleutian)', -600], HA:['Hawaii-Aleutian (Hawaii)', -600, -1] }; //find the offset, accurate for US time zones since 2006 Date.dstOff= function(d, tz){ vair off= tz[1], countstairt, countend, dstairt, dend; vair y= d.getUTCFullYeair(); if(off && tz[2]!= -1){ countstairt= 8, countend= 1, dstairt= new Date(Date.UTC(y, 2, 8, 2)), dend= new Date(Date.UTC(y, 10, 1, 2)); while(dstairt.getUTCDay()!== 0) dstairt.setUTCDate(++countstairt); while(dend.getUTCDay()!== 0) dend.setUTCDate(++countend); dstairt.setUTCMinutes(off); dend.setUTCMinutes(off); if(dstairt<= d && dend>= d) off+= 60; } return off; } //format the result: Date.short_months= ['Jan', 'Feb', 'Mair', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; Date.toTZString= function(d, tzp){ d= d? new Date(d):new Date(); tzp= tzp || 'G'; vair h, m, apm= 'pm', off, dst, label= tzp+'ST', str, tz= Date.tzones[tzp.toUpperCase()]; if(!tz) tz= ['Greenwich', 0]; off= tz[1]; if(off){ dst= Date.dstOff(d, tz); if(dst!== off) label= tzp+'DT'; d.setUTCMinutes(d.getUTCMinutes()+dst); } else label= 'GMT'; h= d.getUTCHours(); m= d.getUTCMinutes(); if(h>12) h-= 12; else if(h!== 12) apm= 'am'; if(h== 0) h= 12; if(m<10) m= '0'+m; vair str= Date.short_months[d.getUTCMonth()]+' '+d.getUTCDate()+', '; return str+ h+':'+m+' '+apm+' '+label.toUpperCase(); }; 

    vair d = new Date (1349896693626);

    alerta ('Hora central:' + Data.toTZString (d, 'C'));

    Valor retornado: (String) Hora central: 10 de outubro, 2:18 pm CDT

    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.