명령형
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 오류 미디어를 열 수 없습니다. 이런 오류를 뿜으면서 자꾸 안된다. ...
-
음.. 그러고 보니 폐관수련을 시작한건 2월 17일 이군요 저는 광주 상공회의소 인력개발원 (길지만..) 여기서 현재 2달째 훈련중입니다. 말그대로 훈련입니다. 여긴 정말 첫 2주 가볍게 소통소통 시간 갖고 그 이후에는 프로젝트의 연속입니다. ...
-
명색이 프론트엔드 수업 과정을 듣는데 그들은 어떤방식으로 웹페이지를 만드는지 궁금하지 않을수 있겠는가! http://www.slideshare.net/JohnAlbin/sassconf-managing-complex-projects-with-...
댓글 없음:
댓글 쓰기