31
29

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.

strftimeで月を表示する際に、0による左詰めパディングを回避する方法

Posted at

##通常

Time.mktime(2012, 1, 1).strftime('%m') # => '01'

##をつけた場合
頭に(
)を付けて%mを呼び出すと0の代わりに半角スペースが補完される。

Time.mktime(2012, 1, 1).strftime('%_m') # => ' 1'

##-をつけた場合

頭に(-)を付けて%mを呼び出すと0なしで出力される。

Time.mktime(2012, 1, 1).strftime('%-m') # => '1'
31
29
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
31
29

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?