R Markdown で新規作成すると、ヘッダに日付が入力されるが、それを「現在の日時」にする方法。
現在の日付を記入: Sys.Date()
Sys.Date()
で、現在の日付を挿入できる。
私が設定している方法は下記 ▼
--- title: "title" author: "mom-doc" data: '`r format(Sys.Date(), "%B %d, %Y")`' ---
チャンクで入れる場合は下記 ▼
Input:```{r}
# print today's date
today <- Sys.Date() format(today, format="%B %d %Y")
```
Output:"Jan 1 2021"
現在の日時を記入: Sys.time()
「現在時刻」は
Sys.time()
で記入できる。
Input:
```{r}
# print today's date and time
mytime <- Sys.time()
format(mytime, format="%a %b %d %X %Y" )
```
Output:"Fri Apr 16 11:16:06 PM 2021"
選択肢の色々
| Symbol | Meaning | Example |
|---|---|---|
| %d | day as a number (0-31) | 01-31 |
| %a | abbreviated weekday | Mon |
| %A | unabbreviated weekday | Monday |
| %m | month (00-12) 00-12 | 00-12 |
| %B | abbreviated month | Jan |
| %b | unabbreviated month | January |
| %y | 2-digit year | 21 |
| %Y | 4-digit year | 2021 |
References
Sys.Date( ) returns today's date. date() returns the current date and time. The following symbols can be used with the format( ) function to print dates.
Description Sys.time and Sys.Date returns the system's idea of the current date with and without time. Usage Sys.time() Sys.Date()
リンク
リンク
リンク
リンク





