Skip to content

Instantly share code, notes, and snippets.

@darui00kara
Created May 22, 2015 05:43
Show Gist options
  • Save darui00kara/1be09aebcdd39f5acf03 to your computer and use it in GitHub Desktop.
Save darui00kara/1be09aebcdd39f5acf03 to your computer and use it in GitHub Desktop.
# 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