How to remove milliseconds in the POSIXct data output in an inline R code in a Note

If you use an inline R code to show POSIXct data in a Note such as using now() function, you see milliseconds in the output like 2023-05-31 15:42:23.534227.

You can use the format() function to format the output. For example, if you want to show the date and time in the same format without milliseconds, you can use format(now(), "%Y-%m-%d %H:%M:%S").

Here is the list of formatting strings that you can use in the format() function.

Formatting String Meaning
%a Abbreviated weekday
%A Full weekday
%b Abbreviated month
%B Full month
%c Locale-specific date and time
%d Decimal date
%H Decimal hours (24 hour)
%I Decimal hours (12 hour)
%j Decimal day of the year
%m Decimal month
%M Decimal minute
%p Locale-specific AM/PM
%S Decimal second
%U Decimal week of the year (starting on Sunday)
%w Decimal Weekday (0=Sunday)
%W Decimal week of the year (starting on Monday)
%x Locale-specific Date
%X Locale-specific Time
%y 2-digit year
%Y 4-digit year
%z Offset from GMT
%Z Time zone (character)