1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ruby date format変換 YYYY-MM-DD => YYYY年MM月

Last updated at Posted at 2016-12-10

きっと2度と見返さないメモ

YYYY-MM-DD => YYYY年MM月

[]:~/ irb
irb(main):001:0> require 'date'
=> true
irb(main):002:0> d = '2016-12-10'
=> "2016-12-10"
irb(main):003:0> x = DateTime.parse(d)
=> #<DateTime: 2016-12-10T00:00:00+00:00 ((2457733j,0s,0n),+0s,2299161j)>
irb(main):004:0> str = x.strftime("%Y年%m月")
=> "2016年12月"
irb(main):005:0>
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?