명령형
setInterval(logClockTime, 1000);
function logClockTime(){
var time = getClockTime();
console.clear();
console.log(time);
}
function getClockTime(){
// 현재 시각을 얻는다.
var date = new Date();
var time = "";
//시각을 직렬화 한다.
var time ={
hours : date.getHours(),
minutes : date.getMinutes(),
seconds: date.getSeconds(),
ampm: "AM"
};
//상용시로 변환한다.
if(time.hours ==12){
time.ampm = "PM";
}else if ( time.hours > 12){
time.ampm = "PM";
time.hour -= 12;
}
//시간을 2글자로 만들기 위해 앞에 0을 붙인다.
if(time.hours <10){
time.hours = "0" + time.hours;
}
//분을 2글자로 만들기 위해 앞에 0을 붙인다.
if(time.minutes < 10){
time.hours = "0"+ time.minutes;
}
//초를 2글자로 만들기 위해 앞에0을 붙인다.
if(time.seconds <10){
time.seconds = "0" + time.seconds;
}
//" hh:mm:ss tt " 형식의 문자열을 만든다.
return time.hours + ":"
+time.minutes+":"
+time.seconds + " "
+time.ampm;
}
선언형
const abstractClockTime = date => ({
hours: date.getHours(),
minutes: date.getMinutes(),
seconds: date.getSeconds()
})
const civilianHours = clockTime => ({
...clockTime,
hours: (clockTime.hours > 12)? clockTime.hours - 12: clockTime.hours
})
const appendAMPM = clockTime => ({
...clockTime,
ampm: (clockTime.hours >= 12 ) ? "PM":"AM"
})
const display = target => time => target(time)
const formatClock = format => time => format.replace("hh", time.hours)
.replace("mm", time.minutes)
.replace("ss", time.seconds)
.replace("tt", time.ampm)
const prependZero = key => clockTime =>
({
...clockTime,
[key]:(clockTime[key] < 10)? "0" + clockTime[key]:clockTime[key]
})
const convertToCivilianTime = clockTime =>
compose(appendAMPM, civilianHours)(clockTime)
const doubleDigits = civilianTime =>
compose(
prependZero("hours"),
prependZero("minutes"),
prependZero("seconds")
)(civilianTime)
const startTicking =() =>
setInterval(
compose(
clear,
getCurrentTime,
abstractClockTime,
convertToCivilianTime,
doubleDigits,
formatClock("hh:mm:ss tt"),
display(log)
),
oneSecond()
)
startTicking()
피드 구독하기:
댓글 (Atom)
-
운영체제를 다시 설치할때 보통 윈도우 인스톨러인가 UUI ? 뭐 정확히는몰라도 여러가지 프로그램을 사용하는데 이번에 rufus 라는 프로그램을 접하게 되었다. rufus 오류 미디어를 열 수 없습니다. 이런 오류를 뿜으면서 자꾸 안된다. ...
-
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2) Posted on 22/04/2015 by Admin | Leave ...
-
타입스크립트 관련 이유없이 빨간줄이간다. 설정과 관련이 있는데 tsconfig.json이나 systemjs.config.js 에서 experimentalDecorators: true 설정을넣어줘도 안없어진다. 비쥬얼 스튜디오 코드 설...
댓글 없음:
댓글 쓰기