{
    "mode": "perldoc",
    "parameter": "Log::Log4perl::DateFormat",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Log%3A%3ALog4perl%3A%3ADateFormat/json",
    "generated": "2026-06-10T13:43:50Z",
    "synopsis": "# Either in a log4j.conf file ...\nlog4perl.appender.Logfile.layout = \\\nLog::Log4perl::Layout::PatternLayout\nlog4perl.appender.Logfile.layout.ConversionPattern = %d{MM/dd HH:mm} %m\n# ... or via the PatternLayout class ...\nuse Log::Log4perl::Layout::PatternLayout;\nmy $layout = Log::Log4perl::Layout::PatternLayout->new(\n\"%d{HH:mm:ss,SSS} %m\");\n# ... or even directly with this helper class:\nuse Log::Log4perl::DateFormat;\nmy $format = Log::Log4perl::DateFormat->new(\"HH:mm:ss,SSS\");\nmy $time = time();\nprint $format->format($time), \"\\n\";\n# => \"17:02:39,000\"",
    "sections": {
        "NAME": {
            "content": "Log::Log4perl::DateFormat - Log4perl advanced date formatter helper class\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "# Either in a log4j.conf file ...\nlog4perl.appender.Logfile.layout = \\\nLog::Log4perl::Layout::PatternLayout\nlog4perl.appender.Logfile.layout.ConversionPattern = %d{MM/dd HH:mm} %m\n\n# ... or via the PatternLayout class ...\nuse Log::Log4perl::Layout::PatternLayout;\nmy $layout = Log::Log4perl::Layout::PatternLayout->new(\n\"%d{HH:mm:ss,SSS} %m\");\n\n# ... or even directly with this helper class:\nuse Log::Log4perl::DateFormat;\nmy $format = Log::Log4perl::DateFormat->new(\"HH:mm:ss,SSS\");\nmy $time = time();\nprint $format->format($time), \"\\n\";\n# => \"17:02:39,000\"\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"Log::Log4perl::DateFormat\" is a helper class for the advanced date formatting functions in\n\"Log::Log4perl::Layout::PatternLayout\", and adheres (mostly) to the log4j SimpleDateFormat spec\navailable on\n\nhttp://download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html\n\nIt supports the following placeholders:\n\nSymbol Meaning              Presentation    Example\n------ -------              ------------    -------\nG      era designator       (Text)          AD\ne      epoch seconds        (Number)        1315011604\ny      year                 (Number)        1996\nM      month in year        (Text & Number) July & 07\nd      day in month         (Number)        10\nh      hour in am/pm (1~12) (Number)        12\nH      hour in day (0~23)   (Number)        0\nm      minute in hour       (Number)        30\ns      second in minute     (Number)        55\nS      millisecond          (Number)        978\nE      day in week          (Text)          Tuesday\nD      day in year          (Number)        189\nF      day of week in month (Number)        2 (2nd Wed in July)\nw      week in year         (Number)        27\nW      week in month        (Number)        2\na      am/pm marker         (Text)          PM\nk      hour in day (1~24)   (Number)        24\nK      hour in am/pm (0~11) (Number)        0\nz      time zone            (Text)          Pacific Standard Time\nZ      RFC 822 time zone    (Text)          -0800\n'      escape for text      (Delimiter)\n''     single quote         (Literal)       '\n\nPresentation explanation:\n\n(Text): 4 or more pattern letters--use full form, < 4--use short or\nabbreviated form if one exists.\n\n(Number): the minimum number of digits. Shorter numbers are\nzero-padded to this amount. Year is handled\nspecially; that is, if the count of 'y' is 2, the\nYear will be truncated to 2 digits.\n\n(Text & Number): 3 or over, use text, otherwise use number.\n\nFor example, if you want to format the current Unix time in \"MM/dd HH:mm\" format, all you have\nto do is specify it in the %d{...} section of the PatternLayout in a Log4perl configuration\nfile:\n\n# log4j.conf\n# ...\nlog4perl.appender.Logfile.layout = \\\nLog::Log4perl::Layout::PatternLayout\nlog4perl.appender.Logfile.layout.ConversionPattern = %d{MM/dd HH:mm} %m\n\nSame goes for Perl code defining a PatternLayout for Log4perl:\n\nuse Log::Log4perl::Layout::PatternLayout;\nmy $layout = Log::Log4perl::Layout::PatternLayout->new(\n\"%d{MM/dd HH:mm} %m\");\n\nOr, on a lower level, you can use the class directly:\n\nuse Log::Log4perl::DateFormat;\nmy $format = Log::Log4perl::DateFormat->new(\"MM/dd HH:mm\");\nmy $time = time();\nprint $format->format($time), \"\\n\";\n\nWhile the \"new()\" method is expensive, because it parses the format strings and sets up all\nkinds of structures behind the scenes, followup calls to \"format()\" are fast, because\n\"DateFormat\" will just call \"localtime()\" and \"sprintf()\" once to return the formatted date/time\nstring.\n\nSo, typically, you would initialize the formatter once and then reuse it over and over again to\ndisplay all kinds of time values.\n\nAlso, for your convenience, the following predefined formats are available, just as outlined in\nthe log4j spec:\n\nFormat   Equivalent                     Example\nABSOLUTE \"HH:mm:ss,SSS\"                 \"15:49:37,459\"\nDATE     \"dd MMM yyyy HH:mm:ss,SSS\"     \"06 Nov 1994 15:49:37,459\"\nISO8601  \"yyyy-MM-dd HH:mm:ss,SSS\"      \"1999-11-27 15:49:37,459\"\nAPACHE   \"[EEE MMM dd HH:mm:ss yyyy]\"   \"[Wed Mar 16 15:49:37 2005]\"\n\nSo, instead of passing\n\nLog::Log4perl::DateFormat->new(\"HH:mm:ss,SSS\");\n\nyou could just as well say\n\nLog::Log4perl::DateFormat->new(\"ABSOLUTE\");\n\nand get the same result later on.\n",
            "subsections": [
                {
                    "name": "Known Shortcomings",
                    "content": "The following placeholders are currently *not* recognized, unless someone (and that could be you\n:) implements them:\n\nF day of week in month\nw week in year\nW week in month\nk hour in day\nK hour in am/pm\nz timezone (but we got 'Z' for the numeric time zone value)\n\nAlso, \"Log::Log4perl::DateFormat\" just knows about English week and month names,\ninternationalization support has to be added.\n"
                }
            ]
        },
        "Millisecond Times": {
            "content": "More granular timestamps down to the millisecond are also supported, just provide the millsecond\ncount as a second argument:\n\n# Advanced time, resoluion in milliseconds\nuse Time::HiRes;\nmy ($secs, $msecs) = Time::HiRes::gettimeofday();\nprint $format->format($secs, $msecs), \"\\n\";\n# => \"17:02:39,959\"\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "Copyright 2002-2016 by Mike Schilli <m@perlmeister.com> and Kevin Goess <cpan@goess.org>.\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Please contribute patches to the project on Github:\n\nhttp://github.com/mschilli/log4perl\n\nSend bug reports or requests for enhancements to the authors via our\n\nMAILING LIST (questions, bug reports, suggestions/patches): log4perl-devel@lists.sourceforge.net\n\nAuthors (please contact them via the list above, not directly): Mike Schilli\n<m@perlmeister.com>, Kevin Goess <cpan@goess.org>\n\nContributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp,\nHutton Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon,\nCarl Franks, Dennis Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier David Hull,\nRobert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter, Brett Rann, Peter Rabbitson, Erik\nSelberg, Aaron Straup Cope, Lars Thegler, David Viner, Mac Yang.\n",
            "subsections": []
        }
    },
    "summary": "Log::Log4perl::DateFormat - Log4perl advanced date formatter helper class",
    "flags": [],
    "examples": [],
    "see_also": []
}