LoginSignup
0
1

More than 5 years have passed since last update.

GNU coreutils > date > 20170228_23000という文字列(UTC)に9.5時間を追加してdateで識別する > echo "20170228_230000" | sed 's/_/+/g' | sed 's/0000/hours\+570minutes/g' | xargs date -d

Last updated at Posted at 2017-10-04
動作環境
Xeon E5-2620 v4 (8コア) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 とその-devel
mpich.x86_64 3.1-5.el6とその-devel
gcc version 4.4.7 (とgfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.1を使用。
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
Python 3.6.0 on virtualenv

20170228_230000 という文字列をdateで 2017-02-28 23:00:00にする

$ echo "20170228_230000" | sed 's/_/+/g' | sed 's/0000/hours/g' | xargs date -d $1
Tue Feb 28 23:00:00 JST 2017

やっていることは以下。

  • 20170228_230000を20170228+23hoursに変換
  • dateに読みこませて2017-02-28 23:00:00という日時と認識

link

GNU dateには入力日時のフォーマット指定はないようだ。

20170228_23000という文字列(UTC)に9.5時間を追加してdateで識別する

9.5時間 = 570分

$ echo "20170228_230000" | sed 's/_/+/g' | sed 's/0000/hours\+570minutes/g' | xargs date -d
Wed Mar  1 08:30:00 JST 2017

上記の文字列をyyyymmdd_hhnnssの書式で出力しようとすると失敗する。
Python実装の方がいいかもしれない。

0
1
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
0
1