Hello World

Be Happy!

Ruby Time DateTime sample


irb(main):003:0> require 'Time'
=> true
irb(main):004:0> Time.parse("2021-01-08T01:17:03")
=> 2021-01-08 01:17:03 -0800

irb(main):006:0>  require 'active_support/all'
=> true
irb(main):009:0> DateTime.parse("2021-01-08T01:17:03")
=> Fri, 08 Jan 2021 01:17:03 +0000


1. Time and DateTime

irb(main):015:0> Time.now
=> 2021-01-13 09:49:53 -0800
irb(main):016:0> Time.now > DateTime.parse("2021-01-09T22:18:04")
=> true
irb(main):017:0> Time.now < DateTime.parse("2021-01-09T22:18:04")
=> false

2. Time and Time

irb(main):018:0> Time.now > Time.parse("2021-01-09T22:18:04")
=> true
irb(main):019:0> Time.now < Time.parse("2021-01-09T22:18:04")
=> false

3. DateTime and DateTime

irb(main):024:0> DateTime.now
=> Wed, 13 Jan 2021 10:04:38 -0800
irb(main):025:0> DateTime.now > DateTime.parse("2021-01-09T22:18:04")
=> true
irb(main):026:0> DateTime.now < DateTime.parse("2021-01-09T22:18:04")
=> false

What defference Time and DateTime ?

  • System TimeZone : PST UTC-8
  • now
    • irb(main):043:0> Time.now
      => 2021-01-13 10:15:46 -0800
      irb(main):043:0> DateTime.now
      => Wed, 13 Jan 2021 10:15:46 -0800
  • parse
    • irb(main):030:0> Time.parse("2021-01-09T22:18:04")
      => 2021-01-09 22:18:04 -0800
      irb(main):029:0> DateTime.parse("2021-01-09T22:18:04")
      => Sat, 09 Jan 2021 22:18:04 +0000

#ruby (9) #irb (2) #time (1) #datetime (1)
List