일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
- 티스토리챌린지
- 오블완
- 려려
- conda 가상환경 설정 오류
- conda base 활성화
- 3000 port kill
- time wait port kill
- window netstat time wait 제거
- 실행중인 포트 죽이기
- conda base 기본 설정
- conda 기초 설정
- Today
- Total
모도리는 공부중
[JAVASCRIPT] TIMESTAMP 본문
new Date()를 이용하는 방법과 moment라는 npm module을 이용하는 방법이 있다.
깔끔한 정리는 나중에 할 예정. 일단은 메모메모.
new Date()를 통해 function을 만들어서 내게 알맞는 형태로 제작한 코드
function dayTimeStamp() {
let str = '';
let currentTime = new Date();
let year = currentTime.getFullYear();
let month = currentTime.getMonth()+1; // javascript의 월은 0월부터 시작하므로 +1
let date = currentTime.getDate();
let hours = currentTime.getHours();
let minutes = currentTime.getMinutes();
let seconds = currentTime.getSeconds();
if (month < 10) month = '0' + month;
if (day < 10) day = '0' + day;
if (hours < 10) hours = '0' + hours;
if (minutes < 10) minutes = '0' + minutes;
if (seconds < 10) seconds = '0' + seconds;
str += '_'+year+month+day+'_'+hours+minutes+seconds;
return str;
}
결과
+ 2021.11.06 ) javascript의 월은 0월부터 시작이라는 사실을 늦게 알아챈 결과, 10월로 나왔는데 눈치채지 못했다. 그저 표현해냈다는 기쁨에 지나쳐버린 내 자신.. 😓
코드 수정 후 정상적으로 11월로 표출되는 것을 확인했다. 지금은 위의 코드가 아래와 같이 바뀐 상태이다.
let month = new Date().getMonth();
// ↓↓
let month = new Date().getMonth()+1;
moment 모듈은 추후 활용 예정이며 아직 new Date도 다 파악하지 못하였음.
참고 사이트
https://stackoverflow.com/questions/221294/how-do-you-get-a-timestamp-in-javascript
How do you get a timestamp in JavaScript?
Something similar to Unix's timestamp, that is a single number that represents the current time and date. Either as a number or a string.
stackoverflow.com
https://millo-l.github.io/Nodejs-moment-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0/
[Node.js] moment 사용하기
nodejs에서 moment.js를 사용해보자.
millo-L.github.io