반응형
현재 날짜 / 시간을 DD / MM / YYYY HH : MM 형식으로 가져 오려면 어떻게해야합니까?
현재 날짜와 시간을 DD/MM/YYYY HH:MM
형식으로 가져오고 월을 늘리려면 어떻게해야합니까?
형식 지정은 다음과 같이 수행 할 수 있습니다 (HH : SS 대신 HH : MM을 의미한다고 가정했지만 변경하기 쉽습니다).
Time.now.strftime("%d/%m/%Y %H:%M")
#=> "14/09/2011 14:09"
변화를 위해 업데이트되었습니다.
d = DateTime.now
d.strftime("%d/%m/%Y %H:%M")
#=> "11/06/2017 18:11"
d.next_month.strftime("%d/%m/%Y %H:%M")
#=> "11/07/2017 18:11"
require 'date'
이 btw에 필요합니다 .
require 'date'
current_time = DateTime.now
current_time.strftime "%d/%m/%Y %H:%M"
# => "14/09/2011 17:02"
current_time.next_month.strftime "%d/%m/%Y %H:%M"
# => "14/10/2011 17:02"
time = Time.now.to_s
time = DateTime.parse(time).strftime("%d/%m/%Y %H:%M")
증가 감소 월의 경우 << >> 연산자 사용
예
datetime_month_before = DateTime.parse(time) << 1
datetime_month_before = DateTime.now << 1
날짜 :
#!/usr/bin/ruby -w
date = Time.new
#set 'date' equal to the current date/time.
date = date.day.to_s + "/" + date.month.to_s + "/" + date.year.to_s
#Without this it will output 2015-01-10 11:33:05 +0000; this formats it to display DD/MM/YYYY
puts date
#output the date
위는 예를 들어 10/01/15로 표시됩니다.
그리고 시간 동안
time = Time.new
#set 'time' equal to the current time.
time = time.hour.to_s + ":" + time.min.to_s
#Without this it will output 2015-01-10 11:33:05 +0000; this formats it to display hour and minute
puts time
#output the time
위는 예를 들어 11:33으로 표시됩니다.
그런 다음 합치려면 끝에 추가하십시오.
puts date + " " + time
반응형
'Programming' 카테고리의 다른 글
서블릿 필터로 요청 매개 변수 수정 (0) | 2020.08.09 |
---|---|
Java의 가변 길이 (동적) 배열 (0) | 2020.08.09 |
Linux에서 파일 끝에 줄을 추가하는 방법 (0) | 2020.08.09 |
Python의 다른 함수 내에서 호출자 함수 이름을 얻습니까? (0) | 2020.08.09 |
Java의 표준 입력에서 정수 값을 읽는 방법 (0) | 2020.08.09 |