4
4

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.

date(gnu)コマンドで月初と月末のepoctime取得

Posted at

date -d"$(date +%Y-%m-1)" +%s
date -d"$(date +%Y-%m-1) +1 month -1 sec" +%s

※ +-1 monthの処理の注意点
3/31 の1ヶ月前は3/3 になったりする(2月の日数28日をマイナスしている?)ので
当月の1日~28日あたりを指定して +-1 month すると安定する模様。

$ date -d"2014/3/31 -1 month"
Mon Mar  3 00:00:00 JST 2014
$ date -d"2014/1/31 +1 month"
Mon Mar  3 00:00:00 JST 2014
$ date -d"2014/7/31 -1 month"
Tue Jul  1 00:00:00 JST 2014
```


## 補足 date -d (--date) でよく使うもの
### n日後(前)
 `` date -d "+-n day" `` 
+は省略可 -は ago でも表記可能 1 day ago的な。でも嫌い。
年月週日時分秒はyear,month,week,day,hour,min,sec

### 今週/先週/来週の月曜日
`` date -d "this mon" `` 
`` date -d "last mon" `` 
`` date -d "next mon" ``
曜日表現は sun,mon,tue,wed,thu,fri,sat で指定

4
4
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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?