μκ°
μκ°μ΄ νΌλ μ€λ½λ€. 60 μ΄μμ 1 λΆ, 60 λΆμμ 1 μκ°, 24 μκ°μμ ν루 (κ·Έλ¦¬κ³ μ±κ°μ am / pmμ λ§ν κ²λ μμ΅λλ€!).
μμ¦μλ κ·Έλ° μ΄λ¦¬ μμμ μ¬μ§κ° μμΌλ―λ‘ μ°λ¦¬λ μ μΌνκ² ν©λ¦¬μ μΈ λμμ μ±ννκΈ°λ‘ κ²°μ νμ΅λλ€. μ¦, λ§€μΌμ μ 체 λ¨μ 1 κ°λ‘ κ°μ£Όλλ©° λ μ§§μ κ²μ ν΄λΉ λ μ§μ μμλ‘ νμλ©λλ€. μλ₯Ό λ€μ΄ β12:00:00β³μ β0.5βλ‘, β01:23:45β³λ β0.058159βλ‘ μμ± λ μ μμ΅λλ€.
μλ‘μ΄ μμ€ν μ μ΅μν΄μ§λ λ° μκ°μ΄ 걸리λ―λ‘, μλ°©ν₯μΌλ‘ λ³ν ν μμλ νλ‘κ·Έλ¨μ μμ±ν΄μΌν©λλ€.
λμ
βhh : mm : ssβμ ISO-8601 νμμΌλ‘ νλμ μ 곡 ν κ²½μ° μ νν μΈμ΄λ‘ νλ‘κ·Έλ¨μ μμ±νλ©΄ λλ±ν 10 μ§μ λΆμ λ¨μκ° λ°νλ©λλ€. λ§μ°¬κ°μ§λ‘ μμ λΆλΆμ΄ μ£Όμ΄μ§λ©΄ νλ‘κ·Έλ¨μ μ²μ μ§μ λ νλ νμμΌλ‘ μκ°μ λ°νν΄μΌν©λλ€.
λ€μκ³Ό κ°μ κ°μ μ ν μ μμ΅λλ€.
- μ΅μ μ λ ₯ λ° μΆλ ₯ λ²μλ β00:00:00β³μμ β24:00:00β³κΉμ§μ λλ€.
- μμμ μκ° μ λ ₯ λ° μΆλ ₯μ λ²μλ β0βμμ β1βκΉμ§ κ°λ₯νλ©° μμμ μ΄ν 5 μ리 (μ : β0.12345β)κΉμ§ νμ© / μΆλ ₯ ν μ μμ΄μΌν©λλ€. λ μ λ°ν κ²μ΄ νμ©λ©λλ€
- νλ‘κ·Έλ¨μ μ λ ₯μ κΈ°λ°μΌλ‘ μν ν λ³ν λ°©ν₯μ μ μ μμ΄μΌν©λλ€.
- μκ° κ΄λ ¨ κΈ°λ₯ / λΌμ΄λΈλ¬λ¦¬λ₯Ό μ¬μ©ν μ μμ΅λλ€
λΉμ²¨μλ κΈ°μ€μ λ¬μ±νλ κ°μ₯ μ§§μ μ½λλ‘ κ²°μ λ©λλ€. κ·Έλ€μ μ μ΄λ 7 κ°μ μμ§ μΌ λ¨μλ‘, λλ μΆ©λΆν μ μΆμ΄ μμμ λ / λμ μ ν λ κ²μ λλ€.
μ
μ¬κΈ°μ μλμ μΌλ‘ μλͺ» μμ±λ JavaScript μ½λκ° μμ λ‘ μ¬μ©λ©λλ€.
function decimalDay(hms) {
var x, h, m, s;
if (typeof hms === 'string' && hms.indexOf(':') > -1) {
x = hms.split(':');
return (x[0] * 3600 + x[1] * 60 + x[2] * 1) / 86400;
}
h = Math.floor(hms * 24) % 24;
m = Math.floor(hms * 1440) % 60;
s = Math.floor(hms * 86400) % 60;
return (h > 9 ? '' : '0') + h + ':' + (m > 9 ? '' : '0') + m + ':' + (s > 9 ? '' : '0') + s;
}
decimalDay('02:57:46'); // 0.12344907407407407
decimalDay('23:42:12'); // 0.9876388888888888
decimalDay(0.5); // 12:00:00
decimalDay(0.05816); // 01:23:45
λ΅λ³
CJam, 58 56 42 λ°μ΄νΈ
λλ μ΄κ²μ΄ λ무 κΈΈκ³ κ³¨νλ₯Ό λ§μ΄ ν μ μλ€κ³ νμ ν©λλ€. κ·Έλ¬λ μ¬κΈ°μ μ΄λ³΄μκ° μμ΅λλ€.
86400q':/:d_,({60bd\/}{~*i60b{s2Ue[}%':*}?
λ΅λ³
νμ΄μ¬ 2 159 150 141 + 2 = 143 λ°μ΄νΈ
κ°λ¨ν ν΄κ²°μ± μ μλ§λ ν¨μ¬ μ§§μ μ μμ΅λλ€. μλν©λλ€.
βsλ‘ λ¬Άμ΄μΌνλ μ λ ₯μ μ€λͺ νκΈ° μν΄ 2 λ°μ΄νΈλ₯Ό μΆκ°νμ΅λλ€. λν Sp3000μ 8 μ§μλ₯Ό ν΄μνλ eval () κ΄λ ¨ λ¬Έμ λ₯Ό μ§μ νμΌλ©° μμμ λ¨μΆνκ³ map ()μ μ¬μ©νμ¬ μΈμλ₯Ό μ κ±°νλ λ°©λ²μ 보μ¬μ£Όμμ΅λλ€.
n=input();i=float;d=864e2
if':'in n:a,b,c=map(i,n.split(':'));o=a/24+b/1440+c/d
else:n=i(n);o=(':%02d'*3%(n*24,n*1440%60,n*d%60))[1:]
print o
λ΅λ³
μλ° ( ES6 ) 116 110 λ°μ΄νΈ
f=x=>x[0]?([h,m,s]=x.split(':'),+s+m*60+h*3600)/86400:[24,60,60].map(y=>('0'+~~(x*=y)%60).slice(-2)).join(':')
// for snippet demo:
i=prompt();
i=i==+i?+i:i; // convert decimal string to number type
alert(f(i))
λκΈ :
f=x=>
x[0] ? // if x is a string (has a defined property at '0')
([h, m, s] = x.split(':'), // split into hours, minutes, seconds
+s + m*60 + h*3600) // calculate number of seconds
/ 86400 // divide by seconds in a day
: // else
[24, 60, 60]. // array of hours, minutes, seconds
map(y=> // map each with function
('0' + // prepend with string zero
~~(x *= y) // multiply x by y and floor it
% 60 // get remainder
).slice(-2) // get last 2 digits
).join(':') // join resulting array with colons
λ΅λ³
νμ΄μ¬ 3 : 143 λ°μ΄νΈ
i,k,l,m=input(),60,86400,float
if'.'in i:i=m(i)*l;m=(3*':%02d'%(i/k/k,i/k%k,i%k))[1:]
else:a,b,c=map(m,i.split(':'));m=(a*k*k+b*k+c)/l
print(m)
python 2 μ루μ κ³Ό λμΌν λ°μ΄νΈ μμ΄μ§λ§ μνμ λν΄ λ€λ₯Έ μ κ·Ό λ°©μμ μ·¨ν κ² κ°μ΅λλ€.
λ΅λ³
μ€λ¦¬μ 152 143 142 λ°μ΄νΈ
κΈμ, λλ 골νλ₯Ό μν΄μ, βμ€λ¦¬μ (Julian)βμ΄ μλ μ κ·Ό λ°©μμ μ λ°μ΄νΈνλ€. λ λμ (κ°κ²°νμ§λ μμ§λ§) μ κ·Ό λ°©μμ κ°μ λ΄μμ μ°Έμ‘°νμμμ€.
x->(t=[3600,60,1];d=86400;typeof(x)<:String?dot(int(split(x,":")),t)/d:(x*=d;o="";for i=t q,x=xΓ·i,x%i;o*=lpad(int(q),2,0)*":"end;o[1:end-1]))
λ¬Έμμ΄ λλ 64 λΉνΈ λΆλ μμμ μ«μλ₯Ό νμ©νκ³ κ°κ° 64 λΉνΈ λΆλ μμμ μ«μ λλ λ¬Έμμ΄μ 리ν΄νλ μ΄λ¦μλ ν¨μλ₯Ό μμ±ν©λλ€. νΈμΆνλ €λ©΄ μ΄λ¦μ μ§μ νμμμ€ (μ π f=x->...
.
μΈ κ³¨ν + μ€λͺ :
function f(x)
# Construct a vector of the number of seconds in an hour,
# minute, and second
t = [3600, 60, 1]
# Store the number of seconds in 24 hours
d = 86400
# Does the type of x inherit from the type String?
if typeof(x) <: String
# Compute the total number of observed seconds as the
# dot product of the time split into a vector with the
# number of seconds in an hour, minute, and second
s = dot(int(split(x, ":")), t)
# Get the proportion of the day by dividing this by
# the number of seconds in 24 hours
s / d
else
# Convert x to the number of observed seconds
x *= d
# Initialize an output string
o = ""
# Loop over the number of seconds in each time unit
for i in t
# Set q to be the quotient and x to be the remainder
# from x divided by i
q, x = divrem(x, i)
# Append q to o, padded with zeroes as necessary
o *= lpad(int(q), 2, 0) * ":"
end
# o has a trailing :, so return everything up to that
o[1:end-1]
end
end
μ :
julia> f("23:42:12")
0.9876388888888888
julia> f(0.9876388888888888)
"23:42:12"
julia> f(f("23:42:12"))
"23:42:12"
λ΅λ³
C, 137 λ°μ΄νΈ
μ 체 C νλ‘κ·Έλ¨. stdinμμ μ λ ₯μ μ·¨νκ³ stdoutμμ μΆλ ₯μ μ·¨ν©λλ€.
main(c){float a,b;scanf("%f:%f:%d",&a,&b,&c)<3?c=a*86400,printf("%02d:%02d:%02d",c/3600,c/60%60,c%60):printf("%f",a/24+b/1440+c/86400.);}
Ungolfed λ° λκΈ :
int main() {
// b is float to save a . on 1440
float a,b;
// c is int to implicitly cast floats
int c;
// If the input is hh:mm:ss it gets splitted into a, b, c
// Three arguments are filled, so ret = 3
// If the input is a float, it gets stored in a
// scanf stops at the first semicolon and only fills a, so ret = 1
int ret = scanf("%f:%f:%d", &a, &b, &c);
if(ret < 3) {
// Got a float, convert to time
// c = number of seconds from 00:00:00
c = a * 86400;
printf("%02d:%02d:%02d", c/3600, c/60 % 60, c%60);
}
else {
// a = hh, b = mm, c = ss
// In one day there are:
// 24 hours
// 1440 minutes
// 86400 seconds
printf("%f", a/24 + b/1440 + c/86400.);
}
}
λ΅λ³
J, 85 λ°μ΄νΈ
κ²°κ³Ό :
T β12 : 00 : 00 β
0.5
T 0.5
12 0 0
T β12 : 34 : 56 β
0.524259
T 0.524259
12 34 56
T=:3 :'a=.86400 if.1=#y do.>.(24 60 60#:y*a)else.a%~+/3600 60 1*".y#~#:192 24 3 end.'
μ΄ 85