日付処理はshellやPHP、JavaScriptなどによってそれぞれ書式などが違うのでまとめておく。
書式は数字の羅列に統一するので、少しわかりずらいが、必要に応じて「月」「日」や「/」「:」などを入れたり、年月日までにとどめれば良い。
◆shell(bash)で現在の年月日時分秒を取得
1 2 |
NOW=`date +%Y%m%d%H%M%S`; echo $NOW; |
◆PHPで現在の年月日時分秒を取得
1 2 |
$NOW = date("YmdHis"); echo $NOW; |
◆JavaScriptで現在の年月日時分秒を取得
1 2 3 4 5 |
<script type="text/JavaScript"> var _now = new Date(); var NOW = "" + _now.getYear() + ( _now.getMonth()+1) + _now.getDate() + _now.getHours() + _now.getMinutes() + _now.getSeconds(); // Stringオブジェクトとして扱う目的で 「"" +」が必要 alert(NOW); </script> |
◆DOSで現在の年月日時分秒を取得(XP以外では動作しないはず)
1 2 |
set NOW=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2% echo %NOW% |
※表示の都合で「set NOW=」が折り返されて見えるかも知れませんが1行です。
◆Excelで現在の年月日時分秒を取得
A1セルに
1 |
=NOW() |
を入力し、「セルの書式設定」→「表示形式」→「ユーザ定義」にて
1 |
yyyymmdhhmmss |
を設定する。
月のmmと分のmmが同じというのが解せないが前後の解釈をしているのか???
No comments yet. You should be kind and add one!
By submitting a comment you grant typista a perpetual license to reproduce your words and name/web site in attribution. Inappropriate and irrelevant comments will be removed at an admin’s discretion. Your email is used for verification purposes only, it will never be shared.