Help us understand the problem. What is going on with this article?

Time の一部を自由自在に改変したい

More than 5 years have passed since last update.

あの時間に戻れたら…
あの時間に飛ぶことができたら…

そんな願いを叶えてくれる時の魔術師、それが Time#change である。

現在時刻が 2014/01/01 00:00:00 だとします。

now = Time.zone.parse("2014/01/01 00:00:00")
#=> Wed, 01 Jan 2014 00:00:00 JST +09:00

2020年に飛びたいな。

now.change(year: 2020)
#=> Wed, 01 Jan 2020 00:00:00 JST +09:00
now
#=> Wed, 01 Jan 2014 00:00:00 JST +09:00

٩( 'ω' )و 飛べた!

しかし、実際には現在の世界線から別の世界線が派生しただけで、
現在は変えられないのです (つまり破壊的メソッドではない) 。

ちなみに、時間を変えることも可能です。

time.change(hour: 23, min: 59, sec: 59)
#=> Wed, 01 Jan 2014 23:59:59 JST +09:00

オプションで指定できるのは、
:year, :month, :day, :hour, :min, :sec, :usec だそうです。

マイクロ秒まで操作できるなんて、Time#change ちゃんパないの!

QUANON
あんた、マジなんだな?
http://quanon.github.io/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした