Raw format of \pdfcreationdate?

The format of the date string comes from the PDF specification, see section "7.9.4 Dates".

  1. The category codes are the same as the result of \string or \detokenize. All characters except the space have category code 12 (other). The space has category code 10 (space).

  2. The "quotemark" is an ASCII character: APOSTROPHE (U+0027)

  3. The Z is a shortcut for the Universal Time, from the PDF specification:

    the LATIN CAPITAL LETTER Z signifies that local time is equal to UT.


Here's a way to extract the code from the \pdfcreationdate that works in all engines; with XeLaTeX it only provides year, month, day, hour and minute.

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\prop_new:N \g_getdate_data_prop
\str_new:N \g_getdate_pdfdate_str
\cs_if_exist:NTF \pdfcreationdate
 {
  \str_gset:Nx \g_getdate_pdfdate_str { \pdfcreationdate }
 }
 {
  \cs_if_exist:NTF \pdffeedback
   {
    \str_gset:Nx \g_getdate_pdfdate_str { \pdffeedback creationdate }
   }
   {
    \str_gset:Nx \g_getdate_pdfdate_str
     {
      D:
      \int_eval:n { \c_sys_year_int }
      \int_compare:nT { \c_sys_month_int < 10 } { 0 }
      \int_eval:n { \c_sys_month_int }
      \int_compare:nT { \c_sys_day_int < 10 } { 0 }
      \int_eval:n { \c_sys_day_int }
      \int_compare:nT { \c_sys_hour_int < 10 } { 0 }
      \int_eval:n { \c_sys_hour_int }
      \int_compare:nT { \c_sys_minute_int < 10 } { 0 }
      \int_eval:n { \c_sys_minute_int }
     }
   }
 }

\prop_gput:Nnx \g_getdate_data_prop { year }
 {
  \str_range:Nnn \g_getdate_pdfdate_str { 3 } { 6 }
 }
\prop_gput:Nnx \g_getdate_data_prop { month }
 {
  \str_range:Nnn \g_getdate_pdfdate_str { 7 } { 8 }
 }
\prop_gput:Nnx \g_getdate_data_prop { day }
 {
  \str_range:Nnn \g_getdate_pdfdate_str { 9 } { 10 }
 }
\prop_gput:Nnx \g_getdate_data_prop { hour }
 {
  \str_range:Nnn \g_getdate_pdfdate_str { 11 } { 12 }
 }
\prop_gput:Nnx \g_getdate_data_prop { minute }
 {
  \str_range:Nnn \g_getdate_pdfdate_str { 13 } { 14 }
 }
\prop_gput:Nnx \g_getdate_data_prop { second }
 {
  \str_range:Nnn \g_getdate_pdfdate_str { 15 } { 16 }
 }
\prop_gput:Nnx \g_getdate_data_prop { diff }
 {
  \str_range:Nnn \g_getdate_pdfdate_str { 17 } { 17 }
 }
\prop_gput:Nnx \g_getdate_data_prop { hourdiff }
 {
  \str_range:Nnn \g_getdate_pdfdate_str { 18 } { 19 }
 }
\prop_gput:Nnx \g_getdate_data_prop { minutediff }
 {
  \str_range:Nnn \g_getdate_pdfdate_str { 21 } { 22 }
 }

\NewExpandableDocumentCommand{\getdatestring}{}
 {
  \str_use:N \g_getdate_pdfdate_str
 }
\NewExpandableDocumentCommand{\getdate}{m}
 {
  \prop_item:Nn \g_getdate_data_prop { #1 }
 }
\NewExpandableDocumentCommand{\gettimedifference}{}
 {
  \str_if_eq:eeTF { \prop_item:Nn \g_getdate_data_prop {diff} } { Z }
   {
    0
   }
   {
    $\prop_item:Nn \g_getdate_data_prop {diff}$
    \prop_item:Nn \g_getdate_data_prop {hourdiff}
    :
    \prop_item:Nn \g_getdate_data_prop {minutediff}
   }
 }

\ExplSyntaxOff

\begin{document}

The year is \getdate{year}, the time is \getdate{hour}:\getdate{minute}
and the time difference with UTC is \gettimedifference

The full string is \getdatestring

\end{document}

Additional macros for extracting the various pieces of information in a more friendly way can be defined.

Output with my time zone:

enter image description here

Output with UTC time zone:

enter image description here

Tags:

Pdf

Date