난 이제 좀 위해 싸우고 대체하십시오. 저는 변환하시겠습니까 날짜로 객체에는 된다. 이 시기 (utc) 에 있는 내가 전송되므로. 통과할 때마다 된다 '는' 새 날짜 () 는 중국 현지 정보기술 (it) 이 된다. 전화했는데 생성하기에 UTC 객체에는 setTime () '을 사용하여 적절한 시기' 관심용 迈向 조정하십시오 있는 유일한 방법이 있지만, 유용한 것 같다는 투치트링 () '와' 는 문장열 타냐한테 돕는다구요. 내가 만약 pass 를 새로운 그 문자열을 날짜, 그건 UTC, 하지만 싫어하겠어 디이브이 합니다.
new Date( new Date().toUTCString() ).toLocaleString()
제 다음 했으나 차이는 있지만, 현재 시점 현재 시점 및 UTC afaq 시도하시려면 아니였어 볼 수 있는 지역 중 하나.
new Date( new Date().toUTCString() ).getTime() - new Date().getTime()
저한테 아주 작은 차이, 즉 1000년 에서 단지 확증하노라 밀리초입니다.
제안 사항을?
처음 날짜를 설정할 수 있는 것 같아요 - 간단해진다는 솔루션 및 추가 UTC 부서입니까 된다. Say you have a UTC epoch var 저장됩니까 초짜리입니다. '1234567890' 어떤가. 적절한 데이트였어 변환할지 있는 국내 시간대:
var utcSeconds = 1234567890;
var d = new Date(0); // The 0 there is the key, which sets the date to the epoch
d.setUTCSeconds(utcSeconds);
날짜 (my time zone) '금' 은 지금 영업사원이에요 설정되었습니다 13일 2월 2009년 18 ~ 31 gmt 0500 (est) '
1일 1월 1970년 초 에서 시간은 epoch in 밀리초입니다 1일 1월 1970년 '에서 되돌려줍니다 다테리게티메.' (), 그래서. javascript 를 곱하여 시간스탬프와 시간스탬프와 있는 경우, 오는 1000년 변환하십시오 redhat. 된다.
function epochToJsDate(ts){
// ts = epoch timestamp
// returns date obj
return new Date(ts*1000);
}
function jsDateToEpoch(d){
// d = javascript date obj
// returns epoch timestamp
return (d.getTime()-d.getMilliseconds())/1000;
}
현재 세 시간에 변환하십시오 (ms) 를 24 시간. [비활성화합니다 12] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString) 형식으로 옵션을 지정해야 할 수 있습니다.
<! - 언어: bash->.
$ node.exe -e "var date = new Date(Date.now()); console.log(date.toLocaleString('en-GB', { hour12:false } ));"
2/7/2018, 19:35:24
과 JS:
<! - 언어: 자바스크립트 - >.
var date = new Date(Date.now());
console.log(date.toLocaleString('en-GB', { hour12:false } ));
// 2/7/2018, 19:35:24
console.log(date.toLocaleString('en-GB', { hour:'numeric', minute:'numeric', second:'numeric', hour12:false } ));
// 19:35:24
넌 그냥 UTC 로 변환하는 것을 문자열이어야 " local"; 구체화하십시오? 그럴 수도 있죠.
var utc_string = '2011-09-05 20:05:15';
var local_string = (function(dtstr) {
var t0 = new Date(dtstr);
var t1 = Date.parse(t0.toUTCString().replace('GMT', ''));
var t2 = (2 * t0) - t1;
return new Date(t2).toString();
})(utc_string);
가장 간단한 해결책을 찾을 수 있는데, 이 I& # 39 입니다.
var timestamp = Date.now(), // returns milliseconds since epoch time
normalisedTime = new Date(timestamp);
원할 경우 및 날짜 및 시간 없이 로컬 라이브러리를 통해 타임스탬프에 해결하십시오 변환에는 UTC 와 같은 옵션을 아래에서 모멘t.j스, 살펴보겠습니다.
Utc 를 사용하는 애플리케이션을 위한 타임스탬프에 표시하십시오 있지만브라우저에 날짜까지 고려할 때 할 수 있습니다 일광 절약 시간대 및 현지 해당하는 경우. 편집 날짜가 다른 일광 절약 시간제 비록 같은 시간대 까다로운 수 있습니다.
이 '수' 와 '아래' 확장명은 날짜 수 있으며, 이 날짜는 시간대 타임스탬프에 표시하십시오 있습니다. 예를 들어, 비헤이비어는 말하도다 틀렸다니까 밴쿠버의 경우 지난 7월 편집하려는 날짜 또는 12월 편집하려는 .pst 또는 PDT 는 지금까지 it 의미할 수 있다.
내가 이 솔루션을 테스트하려면 스니핏 추천합니까 아래로 코드를 확인할 수 있습니다.
Number.prototype.toLocalDate = function () {
var value = new Date(this);
value.setHours(value.getHours() + (value.getTimezoneOffset() / 60));
return value;
};
Number.prototype.toUTCDate = function () {
var value = new Date(this);
value.setHours(value.getHours() - (value.getTimezoneOffset() / 60));
return value;
};
Date.prototype.getUTCTime = function () {
return this.getTime() - (this.getTimezoneOffset() * 60000);
};
// Adds the timezone and daylight savings if applicable
(1499670000000).toLocalDate();
// Eliminates the timezone and daylight savings if applicable
new Date(2017, 6, 10).getUTCTime();
<! - begin 스니핏: js 숨기십시오: 진정한 콘솔: 진정한 바벨. > 거짓값 -;
// Extending Number
Number.prototype.toLocalDate = function () {
var value = new Date(this);
value.setHours(value.getHours() + (value.getTimezoneOffset() / 60));
return value;
};
Number.prototype.toUTCDate = function () {
var value = new Date(this);
value.setHours(value.getHours() - (value.getTimezoneOffset() / 60));
return value;
};
// Extending Date
Date.prototype.getUTCTime = function () {
return this.getTime() - (this.getTimezoneOffset() * 60000);
};
// Getting the demo to work
document.getElementById('m-to-local-button').addEventListener('click', function () {
var displayElement = document.getElementById('m-to-local-display'),
value = document.getElementById('m-to-local').value,
milliseconds = parseInt(value);
if (typeof milliseconds === 'number')
displayElement.innerText = (milliseconds).toLocalDate().toISOString();
else
displayElement.innerText = 'Set a value';
}, false);
document.getElementById('m-to-utc-button').addEventListener('click', function () {
var displayElement = document.getElementById('m-to-utc-display'),
value = document.getElementById('m-to-utc').value,
milliseconds = parseInt(value);
if (typeof milliseconds === 'number')
displayElement.innerText = (milliseconds).toUTCDate().toISOString();
else
displayElement.innerText = 'Set a value';
}, false);
document.getElementById('date-to-utc-button').addEventListener('click', function () {
var displayElement = document.getElementById('date-to-utc-display'),
yearValue = document.getElementById('date-to-utc-year').value || '1970',
monthValue = document.getElementById('date-to-utc-month').value || '0',
dayValue = document.getElementById('date-to-utc-day').value || '1',
hourValue = document.getElementById('date-to-utc-hour').value || '0',
minuteValue = document.getElementById('date-to-utc-minute').value || '0',
secondValue = document.getElementById('date-to-utc-second').value || '0',
year = parseInt(yearValue),
month = parseInt(monthValue),
day = parseInt(dayValue),
hour = parseInt(hourValue),
minute = parseInt(minuteValue),
second = parseInt(secondValue);
displayElement.innerText = new Date(year, month, day, hour, minute, second).getUTCTime();
}, false);
<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.11/semantic.css" rel="stylesheet"/>
<div class="ui container">
<p></p>
<h3>Milliseconds to local date</h3>
<input id="m-to-local" placeholder="Timestamp" value="0" /> <button id="m-to-local-button">Convert</button>
<em id="m-to-local-display">Set a value</em>
<h3>Milliseconds to UTC date</h3>
<input id="m-to-utc" placeholder="Timestamp" value="0" /> <button id="m-to-utc-button">Convert</button>
<em id="m-to-utc-display">Set a value</em>
<h3>Date to milliseconds in UTC</h3>
<input id="date-to-utc-year" placeholder="Year" style="width: 4em;" />
<input id="date-to-utc-month" placeholder="Month" style="width: 4em;" />
<input id="date-to-utc-day" placeholder="Day" style="width: 4em;" />
<input id="date-to-utc-hour" placeholder="Hour" style="width: 4em;" />
<input id="date-to-utc-minute" placeholder="Minute" style="width: 4em;" />
<input id="date-to-utc-second" placeholder="Second" style="width: 4em;" />
<button id="date-to-utc-button">Convert</button>
<em id="date-to-utc-display">Set the values</em>
</div>
끝 - < 스니핏 >;!
세 시간 (즉 시간 bsbab-unix epoch) 는 1일 1월 1970년 초 이후 그 수가 거의 항상 만기되었습니다 00:00:00 utc (시간) , 일부 여기에 대답을 할 수가 없는 밀리초입니다 어떤 시사했다.
https://en.wikipedia.org/wiki/Unix_time
이에 따라 부여받은 unix 세 시간 값이 될 가능성이 있는 경우 이 같은 초, 모양은 '1547035195'. 이 사람이 읽을 수 있게 하려면 JavaScript 로 변환해야 합니다, 전달할 수 있는 값을 날짜 값은 밀리초입니다 꽂으십시오 (가치) ',' 구성자를 예:
const unixEpochTimeMS = 1547035195 * 1000;
const d = new Date(unixEpochTimeMS);
// Careful, the string output here can vary by implementation...
const strDate = d.toLocaleString();
또한 사용 금지 '하는 구성자를 문자열으로 datetime 표현을 날짜 (.)' 이 필요한 것은 바람직하지 않습니다. (자세한 내용은 링크를 참조).
var utcDate = new Date(incomingUTCepoch);
var date = new Date();
date.setUTCDate(utcDate.getDate());
date.setUTCHours(utcDate.getHours());
date.setUTCMonth(utcDate.getMonth());
date.setUTCMinutes(utcDate.getMinutes());
date.setUTCSeconds(utcDate.getSeconds());
date.setUTCMilliseconds(utcDate.getMilliseconds());
하지만, 좋은 아이디어를 구현됩니까 @amjad 부진을 면치 못했다. 시도하시겠습니까
Date.prototype.setUTCTime = function(UTCTimestamp) {
var UTCDate = new Date(UTCTimestamp);
this.setUTCFullYear(UTCDate.getFullYear(), UTCDate.getMonth(), UTCDate.getDate());
this.setUTCHours(UTCDate.getHours(), UTCDate.getMinutes(), UTCDate.getSeconds(), UTCDate.getMilliseconds());
return this.getTime();
}
',' Epoch_time 감안할 때 사용할 수 있습니다.
// for eg. epoch_time = 1487086694.213
var date = new Date(epoch_time * 1000); // multiply by 1000 for milliseconds
var date_string = date.toLocaleString('en-GB'); // 24 hour format