Created
May 22, 2015 05:43
-
-
Save darui00kara/1be09aebcdd39f5acf03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
# File Name: date_time.rb | |
# Create Day is 2015/05/22 | |
# Last Update Day is 2015/05/22 | |
# Require List | |
require 'time' | |
puts "Timeクラス" | |
time = Time.now | |
puts time | |
puts | |
puts time.to_s | |
puts Time.parse(time.to_s) | |
puts Time.parse("2000/11/11 11:11") | |
puts | |
# タイムスタンプを時間に変換する | |
# to_iで時刻をタイムスタンプに変換している | |
# at(タイムスタンプの値)で時刻に変換している | |
puts time.to_i | |
puts Time.at(time.to_i) | |
puts | |
# parseした文字列をタイムスタンプに変換 | |
str_to_timestamp = Time.parse("2000/11/11 11:11").to_i | |
puts str_to_timestamp | |
puts Time.at(str_to_timestamp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment