{
    "mode": "perldoc",
    "parameter": "DateTime",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/DateTime/json",
    "generated": "2026-06-10T16:21:59Z",
    "synopsis": "use DateTime;\n$dt = DateTime->new(\nyear       => 1964,\nmonth      => 10,\nday        => 16,\nhour       => 16,\nminute     => 12,\nsecond     => 47,\nnanosecond => 500000000,\ntimezone  => 'Asia/Taipei',\n);\n$dt = DateTime->fromepoch( epoch => $epoch );\n$dt = DateTime->now;    # same as ( epoch => time )\n$year  = $dt->year;\n$month = $dt->month;        # 1-12\n$day = $dt->day;            # 1-31\n$dow = $dt->dayofweek;    # 1-7 (Monday is 1)\n$hour   = $dt->hour;        # 0-23\n$minute = $dt->minute;      # 0-59\n$second = $dt->second;      # 0-61 (leap seconds!)\n$doy = $dt->dayofyear;    # 1-366 (leap years)\n$doq = $dt->dayofquarter; # 1..\n$qtr = $dt->quarter;        # 1-4\n# all of the start-at-1 methods above have corresponding start-at-0\n# methods, such as $dt->dayofmonth0, $dt->month0 and so on\n$ymd = $dt->ymd;         # 2002-12-06\n$ymd = $dt->ymd('/');    # 2002/12/06\n$mdy = $dt->mdy;         # 12-06-2002\n$mdy = $dt->mdy('/');    # 12/06/2002\n$dmy = $dt->dmy;         # 06-12-2002\n$dmy = $dt->dmy('/');    # 06/12/2002\n$hms = $dt->hms;         # 14:02:29\n$hms = $dt->hms('!');    # 14!02!29\n$isleap = $dt->isleapyear;\n# these are localizable, see Locales section\n$monthname = $dt->monthname;    # January, February, ...\n$monthabbr = $dt->monthabbr;    # Jan, Feb, ...\n$dayname   = $dt->dayname;      # Monday, Tuesday, ...\n$dayabbr   = $dt->dayabbr;      # Mon, Tue, ...\n# May not work for all possible datetime, see the docs on this\n# method for more details.\n$epochtime = $dt->epoch;\n$dt2 = $dt + $durationobject;\n$dt3 = $dt - $durationobject;\n$durationobject = $dt - $dt2;\n$dt->set( year => 1882 );\n$dt->settimezone('America/Chicago');\n$dt->setformatter($formatter);",
    "sections": {
        "NAME": {
            "content": "DateTime - A date and time object for Perl\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 1.55\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use DateTime;\n\n$dt = DateTime->new(\nyear       => 1964,\nmonth      => 10,\nday        => 16,\nhour       => 16,\nminute     => 12,\nsecond     => 47,\nnanosecond => 500000000,\ntimezone  => 'Asia/Taipei',\n);\n\n$dt = DateTime->fromepoch( epoch => $epoch );\n$dt = DateTime->now;    # same as ( epoch => time )\n\n$year  = $dt->year;\n$month = $dt->month;        # 1-12\n\n$day = $dt->day;            # 1-31\n\n$dow = $dt->dayofweek;    # 1-7 (Monday is 1)\n\n$hour   = $dt->hour;        # 0-23\n$minute = $dt->minute;      # 0-59\n\n$second = $dt->second;      # 0-61 (leap seconds!)\n\n$doy = $dt->dayofyear;    # 1-366 (leap years)\n\n$doq = $dt->dayofquarter; # 1..\n\n$qtr = $dt->quarter;        # 1-4\n\n# all of the start-at-1 methods above have corresponding start-at-0\n# methods, such as $dt->dayofmonth0, $dt->month0 and so on\n\n$ymd = $dt->ymd;         # 2002-12-06\n$ymd = $dt->ymd('/');    # 2002/12/06\n\n$mdy = $dt->mdy;         # 12-06-2002\n$mdy = $dt->mdy('/');    # 12/06/2002\n\n$dmy = $dt->dmy;         # 06-12-2002\n$dmy = $dt->dmy('/');    # 06/12/2002\n\n$hms = $dt->hms;         # 14:02:29\n$hms = $dt->hms('!');    # 14!02!29\n\n$isleap = $dt->isleapyear;\n\n# these are localizable, see Locales section\n$monthname = $dt->monthname;    # January, February, ...\n$monthabbr = $dt->monthabbr;    # Jan, Feb, ...\n$dayname   = $dt->dayname;      # Monday, Tuesday, ...\n$dayabbr   = $dt->dayabbr;      # Mon, Tue, ...\n\n# May not work for all possible datetime, see the docs on this\n# method for more details.\n$epochtime = $dt->epoch;\n\n$dt2 = $dt + $durationobject;\n\n$dt3 = $dt - $durationobject;\n\n$durationobject = $dt - $dt2;\n\n$dt->set( year => 1882 );\n\n$dt->settimezone('America/Chicago');\n\n$dt->setformatter($formatter);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "DateTime is a class for the representation of date/time combinations, and is part of the Perl\nDateTime project.\n\nIt represents the Gregorian calendar, extended backwards in time before its creation (in 1582).\nThis is sometimes known as the \"proleptic Gregorian calendar\". In this calendar, the first day\nof the calendar (the epoch), is the first day of year 1, which corresponds to the date which was\n(incorrectly) believed to be the birth of Jesus Christ.\n\nThe calendar represented does have a year 0, and in that way differs from how dates are often\nwritten using \"BCE/CE\" or \"BC/AD\".\n\nFor infinite datetimes, please see the DateTime::Infinite module.\n",
            "subsections": []
        },
        "USAGE": {
            "content": "0-based Versus 1-based Numbers\nThe \"DateTime\" module follows a simple logic for determining whether or not a given number is\n0-based or 1-based.\n\nMonth, day of month, day of week, and day of year are 1-based. Any method that is 1-based also\nhas an equivalent 0-based method ending in \"0\". So for example, this class provides both\n\"dayofweek\" and \"dayofweek0\" methods.\n\nThe \"dayofweek0\" method still treats Monday as the first day of the week.\n\nAll *time*-related numbers such as hour, minute, and second are 0-based.\n\nYears are neither, as they can be both positive or negative, unlike any other datetime\ncomponent. There *is* a year 0.\n\nThere is no \"quarter0\" method.\n",
            "subsections": [
                {
                    "name": "Error Handling",
                    "content": "Some errors may cause this module to die with an error string. This can only happen when calling\nconstructor methods, methods that change the object, such as \"set\", or methods that take\nparameters. Methods that retrieve information about the object, such as \"year\" or \"epoch\", will\nnever die.\n"
                },
                {
                    "name": "Locales",
                    "content": "All the object methods which return names or abbreviations return data based on a locale. This\nis done by setting the locale when constructing a DateTime object. If this is not set, then\n\"en-US\" is used.\n"
                },
                {
                    "name": "Floating DateTimes",
                    "content": "The default time zone for new DateTime objects, except where stated otherwise, is the \"floating\"\ntime zone. This concept comes from the iCal standard. A floating datetime is one which is not\nanchored to any particular time zone. In addition, floating datetimes do not include leap\nseconds, since we cannot apply them without knowing the datetime's time zone.\n\nThe results of date math and comparison between a floating datetime and one with a real time\nzone are not really valid, because one includes leap seconds and the other does not. Similarly,\nthe results of datetime math between two floating datetimes and two datetimes with time zones\nare not really comparable.\n\nIf you are planning to use any objects with a real time zone, it is strongly recommended that\nyou do not mix these with floating datetimes.\n"
                },
                {
                    "name": "Math",
                    "content": "If you are going to be doing date math, please read the section \"How DateTime Math Works\".\n"
                },
                {
                    "name": "Determining the Local Time Zone Can Be Slow",
                    "content": "If $ENV{TZ} is not set, it may involve reading a number of files in /etc or elsewhere. If you\nknow that the local time zone won't change while your code is running, and you need to make many\nobjects for the local time zone, it is strongly recommended that you retrieve the local time\nzone once and cache it:\n\nour $App::LocalTZ = DateTime::TimeZone->new( name => 'local' );\n\n# then everywhere else\n\nmy $dt = DateTime->new( ..., timezone => $App::LocalTZ );\n\nDateTime itself does not do this internally because local time zones can change, and there's no\ngood way to determine if it's changed without doing all the work to look it up.\n"
                },
                {
                    "name": "Far Future DST",
                    "content": "Do not try to use named time zones (like \"America/Chicago\") with dates very far in the future\n(thousands of years). The current implementation of \"DateTime::TimeZone\" will use a huge amount\nof memory calculating all the DST changes from now until the future date. Use UTC or the\nfloating time zone and you will be safe.\n"
                },
                {
                    "name": "Globally Setting a Default Time Zone",
                    "content": "Warning: This is very dangerous. Do this at your own risk!\n\nBy default, \"DateTime\" uses either the floating time zone or UTC for newly created objects,\ndepending on the constructor.\n\nYou can force \"DateTime\" to use a different time zone by setting the \"PERLDATETIMEDEFAULTTZ\"\nenvironment variable.\n\nAs noted above, this is very dangerous, as it affects all code that creates a \"DateTime\" object,\nincluding modules from CPAN. If those modules expect the normal default, then setting this can\ncause confusing breakage or subtly broken data. Before setting this variable, you are strongly\nencouraged to audit your CPAN dependencies to see how they use \"DateTime\". Try running the test\nsuite for each dependency with this environment variable set before using this in production.\n"
                },
                {
                    "name": "Upper and Lower Bounds",
                    "content": "Internally, dates are represented the number of days before or after 0001-01-01. This is stored\nas an integer, meaning that the upper and lower bounds are based on your Perl's integer size\n($Config{ivsize}).\n\nThe limit on 32-bit systems is around 2^29 days, which gets you to year (+/-)1,469,903. On a\n64-bit system you get 2^62 days, to year (+/-)12,626,367,463,883,278 (12.626 quadrillion).\n"
                }
            ]
        },
        "METHODS": {
            "content": "DateTime provides many methods. The documentation breaks them down into groups based on what\nthey do (constructor, accessors, modifiers, etc.).\n",
            "subsections": [
                {
                    "name": "Constructors",
                    "content": "All constructors can die when invalid parameters are given.\n\nWarnings\nCurrently, constructors will warn if you try to create a far future DateTime (year >= 5000) with\nany time zone besides floating or UTC. This can be very slow if the time zone has future DST\ntransitions that need to be calculated. If the date is sufficiently far in the future this can\nbe *really* slow (minutes).\n\nAll warnings from DateTime use the \"DateTime\" category and can be suppressed with:\n\nno warnings 'DateTime';\n\nThis warning may be removed in the future if DateTime::TimeZone is made much faster.\n\nDateTime->new( ... )\nmy $dt = DateTime->new(\nyear       => 1966,\nmonth      => 10,\nday        => 25,\nhour       => 7,\nminute     => 15,\nsecond     => 47,\nnanosecond => 500000000,\ntimezone  => 'America/Chicago',\n);\n\nThis class method accepts the following parameters:\n\n*   year\n\nAn integer year for the DateTime. This can be any integer number within the valid range for\nyour system (See \"Upper and Lower Bounds\"). This is required.\n\n*   month\n\nAn integer from 1-12. Defaults to 1.\n\n*   day\n\nAn integer from 1-31. The value will be validated based on the month, to prevent creating\ninvalid dates like February 30. Defaults to 1.\n\n*   hour\n\nAn integer from 0-23. Hour 0 is midnight at the beginning of the given date. Defaults to 0.\n\n*   minute\n\nAn integer from 0-59. Defaults to 0.\n\n*   second\n\nAn integer from 0-61. Values of 60 or 61 are only allowed when the specified date and time\nhave a leap second. Defaults to 0.\n\n*   nanosecond\n\nAn integer that is greater than or equal to 0. If this number is greater than 1 billion, it\nwill be normalized into the second value for the DateTime object. Defaults to 0\n\n*   locale\n\nA string containing a locale code, like \"en-US\" or \"zh-Hant-TW\", or an object returned by\n\"DateTime::Locale->load\". See the DateTime::Locale documentation for details. Defaults to\nthe value of \"DateTime->DefaultLocale\", or \"en-US\" if the class default has not been set.\n\n*   timezone\n\nA string containing a time zone name like \"America/Chicago\" or a DateTime::TimeZone object.\nDefaults to the value of $ENV{PERLDATETIMEDEFAULTTZ} or \"floating\" if that env var is not\nset. See \"Globally Setting a Default Time Zone\" for more details on that env var (and why\nyou should not use it).\n\nA string will simply be passed to the \"DateTime::TimeZone->new\" method as its \"name\"\nparameter. This string may be an Olson DB time zone name (\"America/Chicago\"), an offset\nstring (\"+0630\"), or the words \"floating\" or \"local\". See the \"DateTime::TimeZone\"\ndocumentation for more details.\n\n*   formatter\n\nAn object or class name with a \"formatdatetime\" method. This will be used to stringify the\nDateTime object. This is optional. If it is not specified, then stringification calls\n\"$self->iso8601\".\n\nInvalid parameter types (like an array reference) will cause the constructor to die.\n\nParsing Dates\nThis module does not parse dates! That means there is no constructor to which you can pass\nthings like \"March 3, 1970 12:34\".\n\nInstead, take a look at the various DateTime::Format::*\n<https://metacpan.org/search?q=datetime%3A%3Aformat> modules on CPAN. These parse all sorts of\ndifferent date formats, and you're bound to find something that can handle your particular\nneeds.\n\nAmbiguous Local Times\nBecause of Daylight Saving Time, it is possible to specify a local time that is ambiguous. For\nexample, in the US in 2003, the transition from to saving to standard time occurred on October\n26, at 02:00:00 local time. The local clock changed from 01:59:59 (saving time) to 01:00:00\n(standard time). This means that the hour from 01:00:00 through 01:59:59 actually occurs twice,\nthough the UTC time continues to move forward.\n\nIf you specify an ambiguous time, then the latest UTC time is always used, in effect always\nchoosing standard time. In this case, you can simply subtract an hour from the object in order\nto move to saving time, for example:\n\n# This object represent 01:30:00 standard time\nmy $dt = DateTime->new(\nyear      => 2003,\nmonth     => 10,\nday       => 26,\nhour      => 1,\nminute    => 30,\nsecond    => 0,\ntimezone => 'America/Chicago',\n);\n\nprint $dt->hms;    # prints 01:30:00\n\n# Now the object represent 01:30:00 saving time\n$dt->subtract( hours => 1 );\n\nprint $dt->hms;    # still prints 01:30:00\n\nAlternately, you could create the object with the UTC time zone and then call the\n\"settimezone\" method to change the time zone. This is a good way to ensure that the time is\nnot ambiguous.\n\nInvalid Local Times\nAnother problem introduced by Daylight Saving Time is that certain local times just do not\nexist. For example, in the US in 2003, the transition from standard to saving time occurred on\nApril 6, at the change to 2:00:00 local time. The local clock changed from 01:59:59 (standard\ntime) to 03:00:00 (saving time). This means that there is no 02:00:00 through 02:59:59 on April\n6!\n\nAttempting to create an invalid time currently causes a fatal error.\n\nDateTime->fromepoch( epoch => $epoch, ... )\nThis class method can be used to construct a new DateTime object from an epoch time instead of\ncomponents. Just as with the \"new\" method, it accepts \"timezone\", \"locale\", and \"formatter\"\nparameters.\n\nIf the epoch value is a non-integral value, it will be rounded to nearest microsecond.\n\nBy default, the returned object will be in the UTC time zone.\n\nIf you pass a \"timezone\", then this time zone will be applied *after* the object is\nconstructed. In other words, the epoch value is always interpreted as being in the UTC time\nzone. Here's an example:\n\nmy $dt = DateTime->fromepoch(\nepoch     => 0,\ntimezone => 'Asia/Tokyo'\n);\nsay $dt; # Prints 1970-01-01T09:00:00 as Asia/Tokyo is +09:00 from UTC.\n$dt->settimezone('UTC');\nsay $dt; # Prints 1970-01-01T00:00:00\n\nDateTime->now( ... )\nThis class method is equivalent to calling \"fromepoch\" with the value returned from Perl's\n\"time\" function. Just as with the \"new\" method, it accepts \"timezone\" and \"locale\" parameters.\n\nBy default, the returned object will be in the UTC time zone.\n\nIf you want sub-second resolution, use the DateTime::HiRes module's \"DateTime::HiRes->now\"\nmethod instead.\n\nDateTime->today( ... )\nThis class method is equivalent to:\n\nDateTime->now(@)->truncate( to => 'day' );\n\nDateTime->lastdayofmonth( ... )\nThis constructor takes the same arguments as can be given to the \"new\" method, except for \"day\".\nAdditionally, both \"year\" and \"month\" are required.\n\nDateTime->fromdayofyear( ... )\nThis constructor takes the same arguments as can be given to the \"new\" method, except that it\ndoes not accept a \"month\" or \"day\" argument. Instead, it requires both \"year\" and \"dayofyear\".\nThe day of year must be between 1 and 366, and 366 is only allowed for leap years.\n\nDateTime->fromobject( object => $object, ... )\nThis class method can be used to construct a new DateTime object from any object that implements\nthe \"utcrdvalues\" method. All \"DateTime::Calendar\" modules must implement this method in order\nto provide cross-calendar compatibility. This method accepts a \"locale\" and \"formatter\"\nparameter\n\nIf the object passed to this method has a \"timezone\" method, that is used to set the time zone\nof the newly created \"DateTime\" object.\n\nOtherwise, the returned object will be in the floating time zone.\n\n$dt->clone\nThis object method returns a new object that is replica of the object upon which the method is\ncalled.\n\n\"Get\" Methods\nThis class has many methods for retrieving information about an object.\n\n$dt->year\nReturns the year.\n\n$dt->ceyear\nReturns the year according to the BCE/CE numbering system. The year before year 1 in this system\nis year -1, aka \"1 BCE\".\n\n$dt->eraname\nReturns the long name of the current era, something like \"Before Christ\". See the \"Locales\"\nsection for more details.\n\n$dt->eraabbr\nReturns the abbreviated name of the current era, something like \"BC\". See the \"Locales\" section\nfor more details.\n\n$dt->christianera\nReturns a string, either \"BC\" or \"AD\", according to the year.\n\n$dt->secularera\nReturns a string, either \"BCE\" or \"CE\", according to the year.\n\n$dt->yearwithera\nReturns a string containing the year immediately followed by the appropriate era abbreviation,\nbased on the object's locale. The year is the absolute value of \"ceyear\", so that year 1 is \"1\"\nand year 0 is \"1BC\". See the \"Locales\" section for more details.\n\n$dt->yearwithchristianera\nLike \"yearwithera\", but uses the \"christianera\" method to get the era name.\n\n$dt->yearwithsecularera\nLike \"yearwithera\", but uses the \"secularera\" method to get the era name.\n\n$dt->month\nReturns the month of the year, from 1..12.\n\nAlso available as \"$dt->mon\".\n\n$dt->monthname\nReturns the name of the current month. See the \"Locales\" section for more details.\n\n$dt->monthabbr\nReturns the abbreviated name of the current month. See the \"Locales\" section for more details.\n\n$dt->day\nReturns the day of the month, from 1..31.\n\nAlso available as \"$dt->mday\" and \"$dt->dayofmonth\".\n\n$dt->dayofweek\nReturns the day of the week as a number, from 1..7, with 1 being Monday and 7 being Sunday.\n\nAlso available as \"$dt->wday\" and \"$dt->dow\".\n\n$dt->localdayofweek\nReturns the day of the week as a number, from 1..7. The day corresponding to 1 will vary based\non the locale. See the \"Locales\" section for more details.\n\n$dt->dayname\nReturns the name of the current day of the week. See the \"Locales\" section for more details.\n\n$dt->dayabbr\nReturns the abbreviated name of the current day of the week. See the \"Locales\" section for more\ndetails.\n\n$dt->dayofyear\nReturns the day of the year.\n\nAlso available as \"$dt->doy\".\n\n$dt->quarter\nReturns the quarter of the year, from 1..4.\n\n$dt->quartername\nReturns the name of the current quarter. See the \"Locales\" section for more details.\n\n$dt->quarterabbr\nReturns the abbreviated name of the current quarter. See the \"Locales\" section for more details.\n\n$dt->dayofquarter\nReturns the day of the quarter.\n\nAlso available as \"$dt->doq\".\n\n$dt->weekdayofmonth\nReturns a number from 1..5 indicating which week day of the month this is. For example, June 9,\n2003 is the second Monday of the month, and so this method returns 2 for that date.\n\n$dt->ymd($optionalseparator), $dt->mdy(...), $dt->dmy(...)\nEach method returns the year, month, and day, in the order indicated by the method name. Years\nare zero-padded to four digits. Months and days are 0-padded to two digits.\n\nBy default, the values are separated by a dash (-), but this can be overridden by passing a\nvalue to the method.\n\nThe \"$dt->ymd\" method is also available as \"$dt->date\".\n\n$dt->hour\nReturns the hour of the day, from 0..23.\n\n$dt->hour1\nReturns the hour of the day, from 1..24.\n\n$dt->hour12\nReturns the hour of the day, from 1..12.\n\n$dt->hour120\nReturns the hour of the day, from 0..11.\n\n$dt->amorpm\nReturns the appropriate localized abbreviation, depending on the current hour.\n\n$dt->minute\nReturns the minute of the hour, from 0..59.\n\nAlso available as \"$dt->min\".\n\n$dt->second\nReturns the second, from 0..61. The values 60 and 61 are used for leap seconds.\n\nAlso available as \"$dt->sec\".\n\n$dt->fractionalsecond\nReturns the second, as a real number from 0.0 until 61.999999999\n\nThe values 60 and 61 are used for leap seconds.\n\n$dt->millisecond\nReturns the fractional part of the second as milliseconds (1E-3 seconds).\n\nHalf a second is 500 milliseconds.\n\nThis value will always be rounded down to the nearest integer.\n\n$dt->microsecond\nReturns the fractional part of the second as microseconds (1E-6 seconds).\n\nHalf a second is 500,000 microseconds.\n\nThis value will always be rounded down to the nearest integer.\n\n$dt->nanosecond\nReturns the fractional part of the second as nanoseconds (1E-9 seconds).\n\nHalf a second is 500,000,000 nanoseconds.\n\n$dt->hms($optionalseparator)\nReturns the hour, minute, and second, all zero-padded to two digits. If no separator is\nspecified, a colon (:) is used by default.\n\nAlso available as \"$dt->time\".\n\n$dt->datetime($optionalseparator)\nThis method is equivalent to:\n\n$dt->ymd('-') . 'T' . $dt->hms(':')\n\nThe $optionalseparator parameter allows you to override the separator between the date and\ntime, for e.g. \"$dt->datetime(q{ })\".\n\nThis method is also available as \"$dt->iso8601\", but it's not really a very good ISO8601 format,\nas it lacks a time zone. If called as \"$dt->iso8601\" you cannot change the separator, as ISO8601\nspecifies that \"T\" must be used to separate them.\n\n$dt->rfc3339\nThis formats a datetime in RFC3339 format. This is the same as \"$dt->datetime\" with an added\noffset at the end of the string except if the time zone is the floating time zone.\n\nIf the offset is '+00:00' then this is represented as 'Z'. Otherwise the offset is formatted\nwith a leading sign (+/-) and a colon separated numeric offset with hours and minutes. If the\noffset has a non-zero seconds component, that is also included.\n\n$dt->stringify\nThis method returns a stringified version of the object. It is also how stringification\noverloading is implemented. If the object has a formatter, then its \"formatdatetime\" method is\nused to produce a string. Otherwise, this method calls \"$dt->iso8601\" to produce a string. See\n\"Formatters And Stringification\" for details.\n\n$dt->isleapyear\nThis method returns a boolean value indicating whether or not the datetime object is in a leap\nyear.\n\n$dt->islastdayofmonth\nThis method returns a boolean value indicating whether or not the datetime object is the last\nday of the month.\n\n$dt->islastdayofquarter\nThis method returns a boolean value indicating whether or not the datetime object is the last\nday of the quarter.\n\n$dt->islastdayofyear\nThis method returns a boolean value indicating whether or not the datetime object is the last\nday of the year.\n\n$dt->monthlength\nThis method returns the number of days in the current month.\n\n$dt->quarterlength\nThis method returns the number of days in the current quarter.\n\n$dt->yearlength\nThis method returns the number of days in the current year.\n\n$dt->week\nmy ( $weekyear, $weeknumber ) = $dt->week;\n\nReturns information about the calendar week for the date. The values returned by this method are\nalso available separately through the \"$dt->weekyear\" and \"$dt->weeknumber\" methods.\n\nThe first week of the year is defined by ISO as the one which contains the fourth day of\nJanuary, which is equivalent to saying that it's the first week to overlap the new year by at\nleast four days.\n\nTypically the week year will be the same as the year that the object is in, but dates at the\nvery beginning of a calendar year often end up in the last week of the prior year, and\nsimilarly, the final few days of the year may be placed in the first week of the next year.\n\n$dt->weekyear\nReturns the year of the week. See \"$dt->week\" for details.\n\n$dt->weeknumber\nReturns the week of the year, from 1..53. See \"$dt->week\" for details.\n\n$dt->weekofmonth\nThe week of the month, from 0..5. The first week of the month is the first week that contains a\nThursday. This is based on the ICU definition of week of month, and correlates to the ISO8601\nweek of year definition. A day in the week *before* the week with the first Thursday will be\nweek 0.\n\n$dt->jd, $dt->mjd\nThese return the Julian Day and Modified Julian Day, respectively. The value returned is a\nfloating point number. The fractional portion of the number represents the time portion of the\ndatetime.\n\nThe Julian Day is a count of days since the beginning of the Julian Period, which starts with\nday 0 at noon on January 1, -4712.\n\nThe Modified Julian Day is a count of days since midnight on November 17, 1858.\n\nThese methods always refer to the local time, so the Julian Day is the same for a given datetime\nregardless of its time zone. Or in other words, 2020-12-04T13:01:57 in \"America/Chicago\" has the\nsame Julian Day as 2020-12-04T13:01:57 in \"Asia/Taipei\".\n\n$dt->timezone\nThis returns the DateTime::TimeZone object for the datetime object.\n\n$dt->offset\nThis returns the offset from UTC, in seconds, of the datetime object's time zone.\n\n$dt->isdst\nReturns a boolean indicating whether or not the datetime's time zone is currently in Daylight\nSaving Time or not.\n\n$dt->timezonelongname\nThis is a shortcut for \"$dt->timezone->name\". It's provided so that one can use\n\"%{timezonelongname}\" as a strftime format specifier.\n\n$dt->timezoneshortname\nThis method returns the time zone abbreviation for the current time zone, such as \"PST\" or\n\"GMT\". These names are not definitive, and should not be used in any application intended for\ngeneral use by users around the world. That's because it's possible for multiple time zones to\nhave the same abbreviation.\n\n$dt->strftime( $format, ... )\nThis method implements functionality similar to the \"strftime\" method in C. However, if given\nmultiple format strings, then it will return multiple scalars, one for each format string.\n\nSee the \"strftime Patterns\" section for a list of all possible strftime patterns.\n\nIf you give a pattern that doesn't exist, then it is simply treated as text.\n\nNote that any deviation from the POSIX standard is probably a bug. DateTime should match the\noutput of \"POSIX::strftime\" for any given pattern.\n\n$dt->formatcldr( $format, ... )\nThis method implements formatting based on the CLDR date patterns. If given multiple format\nstrings, then it will return multiple scalars, one for each format string.\n\nSee the \"CLDR Patterns\" section for a list of all possible CLDR patterns.\n\nIf you give a pattern that doesn't exist, then it is simply treated as text.\n\n$dt->epoch\nReturns the UTC epoch value for the datetime object. Datetimes before the start of the epoch\nwill be returned as a negative number.\n\nThe return value from this method is always an integer number of seconds.\n\nSince the epoch does not account for leap seconds, the epoch time for 1972-12-31T23:59:60 (UTC)\nis exactly the same as that for 1973-01-01T00:00:00.\n\n$dt->hiresepoch\nReturns the epoch as a floating point number. The floating point portion of the value represents\nthe nanosecond value of the object. This method is provided for compatibility with the\n\"Time::HiRes\" module.\n\nNote that this method suffers from the imprecision of floating point numbers, and the result may\nend up rounded to an arbitrary degree depending on your platform.\n\nmy $dt = DateTime->new( year => 2012, nanosecond => 4 );\nsay $dt->hiresepoch;\n\nOn my system, this simply prints 1325376000 because adding 0.000000004 to 1325376000 returns\n1325376000.\n\n$dt->isfinite, $dt->isinfinite\nThese methods allow you to distinguish normal datetime objects from infinite ones. Infinite\ndatetime objects are documented in DateTime::Infinite.\n\n$dt->utcrdvalues\nReturns the current UTC Rata Die days, seconds, and nanoseconds as a three element list. This\nexists primarily to allow other calendar modules to create objects based on the values provided\nby this object.\n\n$dt->localrdvalues\nReturns the current local Rata Die days, seconds, and nanoseconds as a three element list. This\nexists for the benefit of other modules which might want to use this information for date math,\nsuch as DateTime::Event::Recurrence.\n\n$dt->leapseconds\nReturns the number of leap seconds that have happened up to the datetime represented by the\nobject. For floating datetimes, this always returns 0.\n\n$dt->utcrdasseconds\nReturns the current UTC Rata Die days and seconds purely as seconds. This number ignores any\nfractional seconds stored in the object, as well as leap seconds.\n\n$dt->locale\nReturns the datetime's DateTime::Locale object.\n\n$dt->formatter\nReturns the current formatter object or class. See \"Formatters And Stringification\" for details.\n\n\"Set\" Methods\nThe remaining methods provided by \"DateTime\", except where otherwise specified, return the\nobject itself, thus making method chaining possible. For example:\n\nmy $dt = DateTime->now->settimezone( 'Australia/Sydney' );\n\nmy $first = DateTime\n->lastdayofmonth( year => 2003, month => 3 )\n->add( days => 1 )\n->subtract( seconds => 1 );\n\n$dt->set( .. )\nThis method can be used to change the local components of a date time. This method accepts any\nparameter allowed by the \"new\" method except for \"locale\" or \"timezone\". Use \"setlocale\" and\n\"settimezone\" for those instead.\n\nThis method performs parameter validation just like the \"new\" method.\n\nDo not use this method to do date math. Use the \"add\" and \"subtract\" methods instead.\n\n$dt->setyear, $dt->setmonth, etc.\nDateTime has a \"set*\" method for every item that can be passed to the constructor:\n\n*   $dt->setyear\n\n*   $dt->setmonth\n\n*   $dt->setday\n\n*   $dt->sethour\n\n*   $dt->setminute\n\n*   $dt->setsecond\n\n*   $dt->setnanosecond\n\nThese are shortcuts to calling \"set\" with a single key. They all take a single parameter.\n\n$dt->truncate( to => ... )\nThis method allows you to reset some of the local time components in the object to their \"zero\"\nvalues. The \"to\" parameter is used to specify which values to truncate, and it may be one of\n\"year\", \"quarter\", \"month\", \"week\", \"localweek\", \"day\", \"hour\", \"minute\", or \"second\".\n\nFor example, if \"month\" is specified, then the local day becomes 1, and the hour, minute, and\nsecond all become 0.\n\nIf \"week\" is given, then the datetime is set to the Monday of the week in which it occurs, and\nthe time components are all set to 0. If you truncate to \"localweek\", then the first day of the\nweek is locale-dependent. For example, in the \"en-US\" locale, the first day of the week is\nSunday.\n\n$dt->setlocale($locale)\nSets the object's locale. You can provide either a locale code like \"en-US\" or an object\nreturned by \"DateTime::Locale->load\".\n\n$dt->settimezone($tz)\nThis method accepts either a time zone object or a string that can be passed as the \"name\"\nparameter to \"DateTime::TimeZone->new\". If the new time zone's offset is different from the old\ntime zone, then the *local* time is adjusted accordingly.\n\nFor example:\n\nmy $dt = DateTime->new(\nyear      => 2000,\nmonth     => 5,\nday       => 10,\nhour      => 15,\nminute    => 15,\ntimezone => 'America/LosAngeles',\n);\n\nprint $dt->hour;    # prints 15\n\n$dt->settimezone('America/Chicago');\n\nprint $dt->hour;    # prints 17\n\nIf the old time zone was a floating time zone, then no adjustments to the local time are made,\nexcept to account for leap seconds. If the new time zone is floating, then the *UTC* time is\nadjusted in order to leave the local time untouched.\n\nFans of Tsai Ming-Liang's films will be happy to know that this does work:\n\nmy $dt = DateTime->now( timezone => 'Asia/Taipei' );\n$dt->settimezone('Europe/Paris');\n\nYes, now we can know \"ni3 na4 bian1 ji2 dian3?\"\n\n$dt->setformatter($formatter)\nSets the formatter for the object. See \"Formatters And Stringification\" for details.\n\nYou can set this to \"undef\" to revert to the default formatter.\n"
                },
                {
                    "name": "Math Methods",
                    "content": "Like the set methods, math related methods always return the object itself, to allow for\nchaining:\n\n$dt->add( days => 1 )->subtract( seconds => 1 );\n\n$dt->durationclass\nThis returns \"DateTime::Duration\", but exists so that a subclass of \"DateTime\" can provide a\ndifferent value.\n\n$dt->addduration($durationobject)\nThis method adds a DateTime::Duration to the current datetime. See the DateTime::Duration docs\nfor more details.\n\n$dt->add( parameters for DateTime::Duration )\nThis method is syntactic sugar around the \"$dt->addduration\" method. It simply creates a new\nDateTime::Duration object using the parameters given, and then calls the \"$dt->addduration\"\nmethod.\n\n$dt->add($durationobject)\nA synonym of \"$dt->addduration($durationobject)\".\n\n$dt->subtractduration($durationobject)\nWhen given a DateTime::Duration object, this method simply calls \"$dur->inverse\" on that object\nand passes that new duration to the \"$self->addduration\" method.\n\n$dt->subtract( DateTime::Duration->new parameters )\nLike \"$dt->add\", this is syntactic sugar for the \"$dt->subtractduration\" method.\n\n$dt->subtract($durationobject)\nA synonym of \"$dt->subtractduration($durationobject)\".\n\n$dt->subtractdatetime($datetime)\nThis method returns a new DateTime::Duration object representing the difference between the two\ndates. The duration is relative to the object from which $datetime is subtracted. For example:\n\n2003-03-15 00:00:00.00000000\n-  2003-02-15 00:00:00.00000000\n-------------------------------\n= 1 month\n\nNote that this duration is not an absolute measure of the amount of time between the two\ndatetimes, because the length of a month varies, as well as due to the presence of leap seconds.\n\nThe returned duration may have deltas for months, days, minutes, seconds, and nanoseconds.\n\n$dt->deltamd($datetime), $dt->deltadays($datetime)\nEach of these methods returns a new DateTime::Duration object representing some portion of the\ndifference between two datetimes. The \"$dt->deltamd\" method returns a duration which contains\nonly the month and day portions of the duration is represented. The \"$dt->deltadays\" method\nreturns a duration which contains only days.\n\nThe \"$dt->deltamd\" and \"$dt->deltadays\" methods truncate the duration so that any fractional\nportion of a day is ignored. Both of these methods operate on the date portion of a datetime\nonly, and so effectively ignore the time zone.\n\nUnlike the subtraction methods, these methods always return a positive (or zero) duration.\n\n$dt->deltams($datetime)\nReturns a duration which contains only minutes and seconds. Any day and month differences are\nconverted to minutes and seconds. This method always returns a positive (or zero) duration.\n\n$dt->subtractdatetimeabsolute($datetime)\nThis method returns a new DateTime::Duration object representing the difference between the two\ndates in seconds and nanoseconds. This is the only way to accurately measure the absolute amount\nof time between two datetimes, since units larger than a second do not represent a fixed number\nof seconds.\n\nNote that because of leap seconds, this may not return the same result as doing this math based\non the value returned by \"$dt->epoch\".\n\n$dt->isbetween( $lower, $upper )\nChecks whether $dt is strictly between two other DateTime objects.\n\n\"Strictly\" means that $dt must be greater than $lower and less than $upper. If it is *equal* to\neither object then this method returns false.\n"
                },
                {
                    "name": "Class Methods",
                    "content": "DateTime->DefaultLocale($locale)\nThis can be used to specify the default locale to be used when creating DateTime objects. If\nunset, then \"en-US\" is used.\n\nThis exists for backwards compatibility, but is probably best avoided. This will change the\ndefault locale for every \"DateTime\" object created in your application, even those created by\nthird party libraries which also use \"DateTime\".\n\nDateTime->compare( $dt1, $dt2 ), DateTime->compareignorefloating( $dt1, $dt2 )\n$cmp = DateTime->compare( $dt1, $dt2 );\n\n$cmp = DateTime->compareignorefloating( $dt1, $dt2 );\n\nThis method compare two DateTime objects. The semantics are compatible with Perl's \"sort\"\nfunction; it returns -1 if \"$dt1 < $dt2\", 0 if \"$dt1 == $dt2\", 1 if \"$dt1 > $dt2\".\n\nIf one of the two DateTime objects has a floating time zone, it will first be converted to the\ntime zone of the other object. This is what you want most of the time, but it can lead to\ninconsistent results when you compare a number of DateTime objects, some of which are floating,\nand some of which are in other time zones.\n\nIf you want to have consistent results (because you want to sort an array of objects, for\nexample), you can use the \"compareignorefloating\" method:\n\n@dates = sort { DateTime->compareignorefloating( $a, $b ) } @dates;\n\nIn this case, objects with a floating time zone will be sorted as if they were UTC times.\n\nSince DateTime objects overload comparison operators, this:\n\n@dates = sort @dates;\n\nis equivalent to this:\n\n@dates = sort { DateTime->compare( $a, $b ) } @dates;\n\nDateTime objects can be compared to any other calendar class that implements the \"utcrdvalues\"\nmethod.\n"
                },
                {
                    "name": "Testing Code That Uses DateTime",
                    "content": "If you are trying to test code that calls uses DateTime, you may want to be to explicitly set\nthe value returned by Perl's \"time\" builtin. This builtin is called by \"DateTime->now\" and\n\"DateTime->today\".\n\nYou can override \"CORE::GLOBAL::time\", but this will only work if you do this before loading\nDateTime. If doing this is inconvenient, you can also override \"DateTime::coretime\":\n\nno warnings 'redefine';\nlocal *DateTime::coretime = sub { return 42 };\n\nDateTime is guaranteed to call this subroutine to get the current \"time\" value. You can also\noverride the \"coretime\" sub in a subclass of DateTime and use that.\n"
                },
                {
                    "name": "How DateTime Math Works",
                    "content": "It's important to have some understanding of how datetime math is implemented in order to\neffectively use this module and DateTime::Duration.\n\nMaking Things Simple\nIf you want to simplify your life and not have to think too hard about the nitty-gritty of\ndatetime math, I have several recommendations:\n\n*   use the floating time zone\n\nIf you do not care about time zones or leap seconds, use the \"floating\" timezone:\n\nmy $dt = DateTime->now( timezone => 'floating' );\n\nMath done on two objects in the floating time zone produces very predictable results.\n\nNote that in most cases you will want to start by creating an object in a specific zone and\n*then* convert it to the floating time zone. When an object goes from a real zone to the\nfloating zone, the time for the object remains the same.\n\nThis means that passing the floating zone to a constructor may not do what you want.\n\nmy $dt = DateTime->now( timezone => 'floating' );\n\nis equivalent to\n\nmy $dt = DateTime->now( timezone => 'UTC' )->settimezone('floating');\n\nThis might not be what you wanted. Instead, you may prefer to do this:\n\nmy $dt = DateTime->now( timezone => 'local' )->settimezone('floating');\n\n*   use UTC for all calculations\n\nIf you do care about time zones (particularly DST) or leap seconds, try to use non-UTC time\nzones for presentation and user input only. Convert to UTC immediately and convert back to\nthe local time zone for presentation:\n\nmy $dt = DateTime->new( %userinput, timezone => $usertz );\n$dt->settimezone('UTC');\n\n# do various operations - store it, retrieve it, add, subtract, etc.\n\n$dt->settimezone($usertz);\nprint $dt->datetime;\n\n*   math on non-UTC time zones\n\nIf you need to do date math on objects with non-UTC time zones, please read the caveats\nbelow carefully. The results \"DateTime\" produces are predictable, correct, and mostly\nintuitive, but datetime math gets very ugly when time zones are involved, and there are a\nfew strange corner cases involving subtraction of two datetimes across a DST change.\n\nIf you can always use the floating or UTC time zones, you can skip ahead to \"Leap Seconds\nand Date Math\"\n\n*   date vs datetime math\n\nIf you only care about the date (calendar) portion of a datetime, you should use either\n\"$dt->deltamd\" or \"$dt->deltadays\", not \"$dt->subtractdatetime\". This will give\npredictable, unsurprising results, free from DST-related complications.\n\n*   $dt->subtractdatetime and $dt->addduration\n\nYou must convert your datetime objects to the UTC time zone before doing date math if you\nwant to make sure that the following formulas are always true:\n\n$dt2 - $dt1 = $dur\n$dt1 + $dur = $dt2\n$dt2 - $dur = $dt1\n\nNote that using \"$dt->deltadays\" ensures that this formula always works, regardless of the\ntime zones of the objects involved, as does using \"$dt->subtractdatetimeabsolute\". Other\nmethods of subtraction are not always reversible.\n\n*   never do math on two objects where only one is in the floating time zone\n\nThe date math code accounts for leap seconds whenever the \"DateTime\" object is not in the\nfloating time zone. If you try to do math where one object is in the floating zone and the\nother isn't, the results will be confusing and wrong.\n\nAdding a Duration to a DateTime\nThe parts of a duration can be broken down into five parts. These are months, days, minutes,\nseconds, and nanoseconds. Adding one month to a date is different than adding 4 weeks or 28, 29,\n30, or 31 days. Similarly, due to DST and leap seconds, adding a day can be different than\nadding 86,400 seconds, and adding a minute is not exactly the same as 60 seconds.\n\nWe cannot convert between these units, except for seconds and nanoseconds, because there is no\nfixed conversion between most pairs of units. That is because of things like leap seconds, DST\nchanges, etc.\n\n\"DateTime\" always adds (or subtracts) days, then months, minutes, and then seconds and\nnanoseconds. If there are any boundary overflows, these are normalized at each step. For the\ndays and months the local (not UTC) values are used. For minutes and seconds, the local values\nare used. This generally just works.\n\nThis means that adding one month and one day to February 28, 2003 will produce the date April 1,\n2003, not March 29, 2003.\n\nmy $dt = DateTime->new( year => 2003, month => 2, day => 28 );\n\n$dt->add( months => 1, days => 1 );\n\n# 2003-04-01 - the result\n\nOn the other hand, if we add months first, and then separately add days, we end up with March\n29, 2003:\n\n$dt->add( months => 1 )->add( days => 1 );\n\n# 2003-03-29\n\nWe see similar strangeness when math crosses a DST boundary:\n\nmy $dt = DateTime->new(\nyear      => 2003,\nmonth     => 4,\nday       => 5,\nhour      => 1,\nminute    => 58,\ntimezone => \"America/Chicago\",\n);\n\n$dt->add( days => 1, minutes => 3 );\n# 2003-04-06 02:01:00\n\n$dt->add( minutes => 3 )->add( days => 1 );\n# 2003-04-06 03:01:00\n\nNote that if you converted the datetime object to UTC first you would get predictable results.\n\nIf you want to know how many seconds a DateTime::Duration object represents, you have to add it\nto a datetime to find out, so you could do:\n\nmy $now   = DateTime->now( timezone => 'UTC' );\nmy $later = $now->clone->addduration($duration);\n\nmy $secondsdur = $later->subtractdatetimeabsolute($now);\n\nThis returns a DateTime::Duration which only contains seconds and nanoseconds.\n\nIf we were add the duration to a different \"DateTime\" object we might get a different number of\nseconds.\n\nDateTime::Duration supports three different end-of-month algorithms for adding months. This\ncomes into play when an addition results in a day past the end of the following month (for\nexample, adding one month to January 30).\n\n# 2010-08-31 + 1 month = 2010-10-01\n$dt->add( months => 1, endofmonth => 'wrap' );\n\n# 2010-01-30 + 1 month = 2010-02-28\n$dt->add( months => 1, endofmonth => 'limit' );\n\n# 2010-04-30 + 1 month = 2010-05-31\n$dt->add( months => 1, endofmonth => 'preserve' );\n\nBy default, it uses \"wrap\" for positive durations and \"preserve\" for negative durations. See\nDateTime::Duration for a detailed explanation of these algorithms.\n\nIf you need to do lots of work with durations, take a look at the DateTime::Format::Duration\nmodule, which lets you present information from durations in many useful ways.\n\nThere are other subtract/delta methods in \"DateTime\" to generate different types of durations.\nThese methods are \"$dt->subtractdatetime\", \"$dt->subtractdatetimeabsolute\", \"$dt->deltamd\",\n\"$dt->deltadays\", and \"$dt->deltams\".\n\nDateTime Subtraction\nDate subtraction is done based solely on the two object's local datetimes, with one exception to\nhandle DST changes. Also, if the two datetime objects are in different time zones, one of them\nis converted to the other's time zone first before subtraction. This is best explained through\nexamples:\n\nThe first of these probably makes the most sense:\n\n# not DST\nmy $dt1 = DateTime->new(\nyear      => 2003,\nmonth     => 5,\nday       => 6,\ntimezone => 'America/Chicago',\n);\n\n# is DST\nmy $dt2 = DateTime->new(\nyear      => 2003,\nmonth     => 11,\nday       => 6,\ntimezone => 'America/Chicago',\n);\n\n# 6 months\nmy $dur = $dt2->subtractdatetime($dt1);\n\nNice and simple.\n\nThis one is a little trickier, but still fairly logical:\n\n# is DST\nmy $dt1 = DateTime->new(\nyear      => 2003,\nmonth     => 4,\nday       => 5,\nhour      => 1,\nminute    => 58,\ntimezone => \"America/Chicago\",\n);\n\n# not DST\nmy $dt2 = DateTime->new(\nyear      => 2003,\nmonth     => 4,\nday       => 7,\nhour      => 2,\nminute    => 1,\ntimezone => \"America/Chicago\",\n);\n\n# 2 days and 3 minutes\nmy $dur = $dt2->subtractdatetime($dt1);\n\nWhich contradicts the result this one gives, even though they both make sense:\n\n# is DST\nmy $dt1 = DateTime->new(\nyear      => 2003,\nmonth     => 4,\nday       => 5,\nhour      => 1,\nminute    => 58,\ntimezone => \"America/Chicago\",\n);\n\n# not DST\nmy $dt2 = DateTime->new(\nyear      => 2003,\nmonth     => 4,\nday       => 6,\nhour      => 3,\nminute    => 1,\ntimezone => \"America/Chicago\",\n);\n\n# 1 day and 3 minutes\nmy $dur = $dt2->subtractdatetime($dt1);\n\nThis last example illustrates the \"DST\" exception mentioned earlier. The exception accounts for\nthe fact 2003-04-06 only lasts 23 hours.\n\nAnd finally:\n\nmy $dt2 = DateTime->new(\nyear      => 2003,\nmonth     => 10,\nday       => 26,\nhour      => 1,\ntimezone => 'America/Chicago',\n);\n\nmy $dt1 = $dt2->clone->subtract( hours => 1 );\n\n# 60 minutes\nmy $dur = $dt2->subtractdatetime($dt1);\n\nThis seems obvious until you realize that subtracting 60 minutes from $dt2 in the above example\nstill leaves the clock time at \"01:00:00\". This time we are accounting for a 25 hour day.\n\nReversibility\nDate math operations are not always reversible. This is because of the way that addition\noperations are ordered. As was discussed earlier, adding 1 day and 3 minutes in one call to\n\"$dt->add\" is not the same as first adding 3 minutes and 1 day in two separate calls.\n\nIf we take a duration returned from \"$dt->subtractdatetime\" and then try to add or subtract\nthat duration from one of the datetimes we just used, we sometimes get interesting results:\n\nmy $dt1 = DateTime->new(\nyear      => 2003,\nmonth     => 4,\nday       => 5,\nhour      => 1,\nminute    => 58,\ntimezone => \"America/Chicago\",\n);\n\nmy $dt2 = DateTime->new(\nyear      => 2003,\nmonth     => 4,\nday       => 6,\nhour      => 3,\nminute    => 1,\ntimezone => \"America/Chicago\",\n);\n\n# 1 day and 3 minutes\nmy $dur = $dt2->subtractdatetime($dt1);\n\n# gives us $dt2\n$dt1->addduration($dur);\n\n# gives us 2003-04-05 02:58:00 - 1 hour later than $dt1\n$dt2->subtractduration($dur);\n\nThe \"$dt->subtractduration\" operation gives us a (perhaps) unexpected answer because it first\nsubtracts one day to get 2003-04-05T03:01:00 and then subtracts 3 minutes to get the final\nresult.\n\nIf we explicitly reverse the order we can get the original value of $dt1. This can be\nfacilitated by the DateTime::Duration class's \"$dur->calendarduration\" and\n\"$dur->clockduration\" methods:\n\n$dt2->subtractduration( $dur->clockduration )\n->subtractduration( $dur->calendarduration );\n\nLeap Seconds and Date Math\nThe presence of leap seconds can cause even more anomalies in date math. For example, the\nfollowing is a legal datetime:\n\nmy $dt = DateTime->new(\nyear      => 1972,\nmonth     => 12,\nday       => 31,\nhour      => 23,\nminute    => 59,\nsecond    => 60,\ntimezone => 'UTC'\n);\n\nIf we add one month ...\n\n$dt->add( months => 1 );\n\n... the datetime is now \"1973-02-01 00:00:00\", because there is no 23:59:60 on 1973-01-31.\n\nLeap seconds also force us to distinguish between minutes and seconds during date math. Given\nthe following datetime ...\n\nmy $dt = DateTime->new(\nyear      => 1972,\nmonth     => 12,\nday       => 31,\nhour      => 23,\nminute    => 59,\nsecond    => 30,\ntimezone => 'UTC'\n);\n\n... we will get different results when adding 1 minute than we get if we add 60 seconds. This is\nbecause in this case, the last minute of the day, beginning at 23:59:00, actually contains 61\nseconds.\n\nHere are the results we get:\n\n# 1972-12-31 23:59:30 - our starting datetime\nmy $dt = DateTime->new(\nyear      => 1972,\nmonth     => 12,\nday       => 31,\nhour      => 23,\nminute    => 59,\nsecond    => 30,\ntimezone => 'UTC'\n);\n\n# 1973-01-01 00:00:30 - one minute later\n$dt->clone->add( minutes => 1 );\n\n# 1973-01-01 00:00:29 - 60 seconds later\n$dt->clone->add( seconds => 60 );\n\n# 1973-01-01 00:00:30 - 61 seconds later\n$dt->clone->add( seconds => 61 );\n\nLocal vs. UTC and 24 hours vs. 1 day\nWhen math crosses a daylight saving boundary, a single day may have more or less than 24 hours.\n\nFor example, if you do this ...\n\nmy $dt = DateTime->new(\nyear      => 2003,\nmonth     => 4,\nday       => 5,\nhour      => 2,\ntimezone => 'America/Chicago',\n);\n\n$dt->add( days => 1 );\n\n... then you will produce an *invalid* local time, and therefore an exception will be thrown.\n\nHowever, this works ...\n\nmy $dt = DateTime->new(\nyear      => 2003,\nmonth     => 4,\nday       => 5,\nhour      => 2,\ntimezone => 'America/Chicago',\n);\n\n$dt->add( hours => 24 );\n\n... and produces a datetime with the local time of \"03:00\".\n\nIf all this makes your head hurt, there is a simple alternative. Just convert your datetime\nobject to the \"UTC\" time zone before doing date math on it, and switch it back to the local time\nzone afterwards. This avoids the possibility of having date math throw an exception, and makes\nsure that 1 day equals 24 hours. Of course, this may not always be desirable, so caveat user!\n"
                },
                {
                    "name": "Overloading",
                    "content": "This module explicitly overloads the addition (+), subtraction (-), string and numeric\ncomparison operators. This means that the following all do sensible things:\n\nmy $newdt = $dt + $durationobj;\n\nmy $newdt = $dt - $durationobj;\n\nmy $durationobj = $dt - $newdt;\n\nfor my $dt ( sort @dts ) {...}\n\nAdditionally, the fallback parameter is set to true, so other derivable operators (+=, -=, etc.)\nwill work properly. Do not expect increment (++) or decrement (--) to do anything useful.\n\nThe string comparison operators, \"eq\" or \"ne\", will use the string value to compare with\nnon-DateTime objects.\n\nDateTime objects do not have a numeric value, using \"==\" or \"<=>\" to compare a DateTime object\nwith a non-DateTime object will result in an exception. To safely sort mixed DateTime and\nnon-DateTime objects, use \"sort { $a cmp $b } @dates\".\n\nThe module also overloads stringification using the object's formatter, defaulting to \"iso8601\"\nmethod. See \"Formatters And Stringification\" for details.\n"
                },
                {
                    "name": "Formatters And Stringification",
                    "content": "You can optionally specify a \"formatter\", which is usually a \"DateTime::Format::*\" object or\nclass, to control the stringification of the DateTime object.\n\nAny of the constructor methods can accept a formatter argument:\n\nmy $formatter = DateTime::Format::Strptime->new(...);\nmy $dt        = DateTime->new( year => 2004, formatter => $formatter );\n\nOr, you can set it afterwards:\n\n$dt->setformatter($formatter);\n$formatter = $dt->formatter;\n\nOnce you set the formatter, the overloaded stringification method will use the formatter. If\nunspecified, the \"iso8601\" method is used.\n\nA formatter can be handy when you know that in your application you want to stringify your\nDateTime objects into a special format all the time, for example in Postgres format.\n\nIf you provide a formatter class name or object, it must implement a \"formatdatetime\" method.\nThis method will be called with just the \"DateTime\" object as its argument.\n\nCLDR Patterns\nThe CLDR pattern language is both more powerful and more complex than strftime. Unlike strftime\npatterns, you often have to explicitly escape text that you do not want formatted, as the\npatterns are simply letters without any prefix.\n\nFor example, \"yyyy-MM-dd\" is a valid CLDR pattern. If you want to include any lower or upper\ncase ASCII characters as-is, you can surround them with single quotes ('). If you want to\ninclude a single quote, you must escape it as two single quotes ('').\n\nmy $pattern1 = q{'Today is ' EEEE};\nmy $pattern2 = q{'It is now' h 'o''clock' a};\n\nSpaces and any non-letter text will always be passed through as-is.\n\nMany CLDR patterns which produce numbers will pad the number with leading zeroes depending on\nthe length of the format specifier. For example, \"h\" represents the current hour from 1-12. If\nyou specify \"hh\" then hours 1-9 will have a leading zero prepended.\n\nHowever, CLDR often uses five of a letter to represent the narrow form of a pattern. This\ninconsistency is necessary for backwards compatibility.\n\nThere are many cases where CLDR patterns distinguish between the \"format\" and \"stand-alone\"\nforms of a pattern. The format pattern is used when the thing in question is being placed into a\nlarger string. The stand-alone form is used when displaying that item by itself, for example in\na calendar.\n\nThere are also many cases where CLDR provides three sizes for each item, wide (the full name),\nabbreviated, and narrow. The narrow form is often just a single character, for example \"T\" for\n\"Tuesday\", and may not be unique.\n\nCLDR provides a fairly complex system for localizing time zones that we ignore entirely. The\ntime zone patterns just use the information provided by \"DateTime::TimeZone\", and *do not follow\nthe CLDR spec*.\n\nThe output of a CLDR pattern is always localized, when applicable.\n\nCLDR provides the following patterns:\n\n*   G{1,3}\n\nThe abbreviated era (BC, AD).\n\n*   GGGG\n\nThe wide era (Before Christ, Anno Domini).\n\n*   GGGGG\n\nThe narrow era, if it exists (but it mostly doesn't).\n\n*   y and y{3,}\n\nThe year, zero-prefixed as needed. Negative years will start with a \"-\", and this will be\nincluded in the length calculation.\n\nIn other, words the \"yyyyy\" pattern will format year -1234 as \"-1234\", not \"-01234\".\n\n*   yy\n\nThis is a special case. It always produces a two-digit year, so \"1976\" becomes \"76\".\nNegative years will start with a \"-\", making them one character longer.\n\n*   Y{1,}\n\nThe year in \"week of the year\" calendars, from \"$dt->weekyear\".\n\n*   u{1,}\n\nSame as \"y\" except that \"uu\" is not a special case.\n\n*   Q{1,2}\n\nThe quarter as a number (1..4).\n\n*   QQQ\n\nThe abbreviated format form for the quarter.\n\n*   QQQQ\n\nThe wide format form for the quarter.\n\n*   q{1,2}\n\nThe quarter as a number (1..4).\n\n*   qqq\n\nThe abbreviated stand-alone form for the quarter.\n\n*   qqqq\n\nThe wide stand-alone form for the quarter.\n\n*   M{1,2}\n\nThe numerical month.\n\n*   MMM\n\nThe abbreviated format form for the month.\n\n*   MMMM\n\nThe wide format form for the month.\n\n*   MMMMM\n\nThe narrow format form for the month.\n\n*   L{1,2}\n\nThe numerical month.\n\n*   LLL\n\nThe abbreviated stand-alone form for the month.\n\n*   LLLL\n\nThe wide stand-alone form for the month.\n\n*   LLLLL\n\nThe narrow stand-alone form for the month.\n\n*   w{1,2}\n\nThe week of the year, from \"$dt->weeknumber\".\n\n*   W\n\nThe week of the month, from \"$dt->weekofmonth\".\n\n*   d{1,2}\n\nThe numeric day of the month.\n\n*   D{1,3}\n\nThe numeric day of the year.\n\n*   F\n\nThe day of the week in the month, from \"$dt->weekdayofmonth\".\n\n*   g{1,}\n\nThe modified Julian day, from \"$dt->mjd\".\n\n*   E{1,3} and eee\n\nThe abbreviated format form for the day of the week.\n\n*   EEEE and eeee\n\nThe wide format form for the day of the week.\n\n*   EEEEE and eeeee\n\nThe narrow format form for the day of the week.\n\n*   e{1,2}\n\nThe *local* numeric day of the week, from 1 to 7. This number depends on what day is\nconsidered the first day of the week, which varies by locale. For example, in the US, Sunday\nis the first day of the week, so this returns 2 for Monday.\n\n*   c\n\nThe numeric day of the week from 1 to 7, treating Monday as the first of the week,\nregardless of locale.\n\n*   ccc\n\nThe abbreviated stand-alone form for the day of the week.\n\n*   cccc\n\nThe wide stand-alone form for the day of the week.\n\n*   ccccc\n\nThe narrow format form for the day of the week.\n\n*   a\n\nThe localized form of AM or PM for the time.\n\n*   h{1,2}\n\nThe hour from 1-12.\n\n*   H{1,2}\n\nThe hour from 0-23.\n\n*   K{1,2}\n\nThe hour from 0-11.\n\n*   k{1,2}\n\nThe hour from 1-24.\n\n*   j{1,2}\n\nThe hour, in 12 or 24 hour form, based on the preferred form for the locale. In other words,\nthis is equivalent to either \"h{1,2}\" or \"H{1,2}\".\n\n*   m{1,2}\n\nThe minute.\n\n*   s{1,2}\n\nThe second.\n\n*   S{1,}\n\nThe fractional portion of the seconds, rounded based on the length of the specifier. This\nreturned *without* a leading decimal point, but may have leading or trailing zeroes.\n\n*   A{1,}\n\nThe millisecond of the day, based on the current time. In other words, if it is 12:00:00.00,\nthis returns 43200000.\n\n*   z{1,3}\n\nThe time zone short name.\n\n*   zzzz\n\nThe time zone long name.\n\n*   Z{1,3}\n\nThe time zone offset.\n\n*   ZZZZ\n\nThe time zone short name and the offset as one string, so something like \"CDT-0500\".\n\n*   ZZZZZ\n\nThe time zone offset as a sexagesimal number, so something like \"-05:00\". (This is useful\nfor W3C format.)\n\n*   v{1,3}\n\nThe time zone short name.\n\n*   vvvv\n\nThe time zone long name.\n\n*   V{1,3}\n\nThe time zone short name.\n\n*   VVVV\n\nThe time zone long name.\n\nCLDR \"Available Formats\"\nThe CLDR data includes pre-defined formats for various patterns such as \"month and day\" or \"time\nof day\". Using these formats lets you render information about a datetime in the most natural\nway for users from a given locale.\n\nThese formats are indexed by a key that is itself a CLDR pattern. When you look these up, you\nget back a different CLDR pattern suitable for the locale.\n\nLet's look at some example We'll use \"2008-02-05T18:30:30\" as our example datetime value, and\nsee how this is rendered for the \"en-US\" and \"fr-FR\" locales.\n\n*   \"MMMd\"\n\nThe abbreviated month and day as number. For \"en-US\", we get the pattern \"MMM d\", which\nrenders as \"Feb 5\". For \"fr-FR\", we get the pattern \"d MMM\", which renders as \"5 févr.\".\n\n*   \"yQQQ\"\n\nThe year and abbreviated quarter of year. For \"en-US\", we get the pattern \"QQQ y\", which\nrenders as \"Q1 2008\". For \"fr-FR\", we get the same pattern, \"QQQ y\", which renders as \"T1\n2008\".\n\n*   \"hm\"\n\nThe 12-hour time of day without seconds. For \"en-US\", we get the pattern \"h:mm a\", which\nrenders as \"6:30 PM\". For \"fr-FR\", we get the exact same pattern and rendering.\n\nThe available formats for each locale are documented in the POD for that locale. To get back the\nformat, you use the \"$locale->formatfor\" method. For example:\n\nsay $dt->formatcldr( $dt->locale->formatfor('MMMd') );\n\nstrftime Patterns\nThe following patterns are allowed in the format string given to the \"$dt->strftime\" method:\n\n*   %a\n\nThe abbreviated weekday name.\n\n*   %A\n\nThe full weekday name.\n\n*   %b\n\nThe abbreviated month name.\n\n*   %B\n\nThe full month name.\n\n*   %c\n\nThe default datetime format for the object's locale.\n\n*   %C\n\nThe century number (year/100) as a 2-digit integer.\n\n*   %d\n\nThe day of the month as a decimal number (range 01 to 31).\n\n*   %D\n\nEquivalent to %m/%d/%y. This is not a good standard format if you want folks from both the\nUnited States and the rest of the world to understand the date!\n\n*   %e\n\nLike %d, the day of the month as a decimal number, but a leading zero is replaced by a\nspace.\n\n*   %F\n\nEquivalent to %Y-%m-%d (the ISO 8601 date format)\n\n*   %G\n\nThe ISO 8601 year with century as a decimal number. The 4-digit year corresponding to the\nISO week number (see %V). This has the same format and value as %Y, except that if the ISO\nweek number belongs to the previous or next year, that year is used instead. (TZ)\n\n*   %g\n\nLike %G, but without century, i.e., with a 2-digit year (00-99).\n\n*   %h\n\nEquivalent to %b.\n\n*   %H\n\nThe hour as a decimal number using a 24-hour clock (range 00 to 23).\n\n*   %I\n\nThe hour as a decimal number using a 12-hour clock (range 01 to 12).\n\n*   %j\n\nThe day of the year as a decimal number (range 001 to 366).\n\n*   %k\n\nThe hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by\na blank. (See also %H.)\n\n*   %l\n\nThe hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by\na blank. (See also %I.)\n\n*   %m\n\nThe month as a decimal number (range 01 to 12).\n\n*   %M\n\nThe minute as a decimal number (range 00 to 59).\n\n*   %n\n\nA newline character.\n\n*   %N\n\nThe fractional seconds digits. Default is 9 digits (nanoseconds).\n\n%3N   milliseconds (3 digits)\n%6N   microseconds (6 digits)\n%9N   nanoseconds  (9 digits)\n\nThis value will always be rounded down to the nearest integer.\n\n*   %p\n\nEither `AM' or `PM' according to the given time value, or the corresponding strings for the\ncurrent locale. Noon is treated as `pm' and midnight as `am'.\n\n*   %P\n\nLike %p but in lowercase: `am' or `pm' or a corresponding string for the current locale.\n\n*   %r\n\nThe time in a.m. or p.m. notation. In the POSIX locale this is equivalent to `%I:%M:%S %p'.\n\n*   %R\n\nThe time in 24-hour notation (%H:%M). (SU) For a version including the seconds, see %T\nbelow.\n\n*   %s\n\nThe number of seconds since the epoch.\n\n*   %S\n\nThe second as a decimal number (range 00 to 61).\n\n*   %t\n\nA tab character.\n\n*   %T\n\nThe time in 24-hour notation (%H:%M:%S).\n\n*   %u\n\nThe day of the week as a decimal, range 1 to 7, Monday being 1. See also %w.\n\n*   %U\n\nThe week number of the current year as a decimal number, range 00 to 53, starting with the\nfirst Sunday as the first day of week 01. See also %V and %W.\n\n*   %V\n\nThe ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where\nweek 1 is the first week that has at least 4 days in the current year, and with Monday as\nthe first day of the week. See also %U and %W.\n\n*   %w\n\nThe day of the week as a decimal, range 0 to 6, Sunday being 0. See also %u.\n\n*   %W\n\nThe week number of the current year as a decimal number, range 00 to 53, starting with the\nfirst Monday as the first day of week 01.\n\n*   %x\n\nThe default date format for the object's locale.\n\n*   %X\n\nThe default time format for the object's locale.\n\n*   %y\n\nThe year as a decimal number without a century (range 00 to 99).\n\n*   %Y\n\nThe year as a decimal number including the century.\n\n*   %z\n\nThe time-zone as hour offset from UTC. Required to emit RFC822-conformant dates (using \"%a,\n%d %b %Y %H:%M:%S %z\").\n\n*   %Z\n\nThe short name for the time zone, typically an abbreviation like \"EST\" or \"AEST\".\n\n*   %%\n\nA literal `%' character.\n\n*   %{method}\n\nAny method name may be specified using the format \"%{method}\" name where \"method\" is a valid\n\"DateTime\" object method.\n"
                },
                {
                    "name": "DateTime and Storable",
                    "content": "\"DateTime\" implements Storable hooks in order to reduce the size of a serialized \"DateTime\"\nobject.\n"
                }
            ]
        },
        "DEVELOPMENT TOOLS": {
            "content": "If you're working on the \"DateTIme\" code base, there are a few extra non-Perl tools that you may\nfind useful, notably precious <https://github.com/houseabsolute/precious>, a meta-linter/tidier.\nYou can install all the necessary tools in \"$HOME/bin\" by running\n./dev-bin/install-dev-tools.sh.\n\nTry running \"precious tidy -a\" to tidy all the tidyable files in the repo, and \"precious lint\n-a\" to run all the lint checks.\n\nYou can enable a git pre-commit hook for linting by running ./git/setup.pl.\n\nNote that linting will be checked in CI, and it's okay to submit a PR which fails the linting\ncheck, but it's extra nice to fix these yourself.\n",
            "subsections": []
        },
        "THE DATETIME PROJECT ECOSYSTEM": {
            "content": "This module is part of a larger ecosystem of modules in the DateTime family.\n",
            "subsections": [
                {
                    "name": "DateTime::Set",
                    "content": "The DateTime::Set module represents sets (including recurrences) of datetimes. Many modules\nreturn sets or recurrences.\n"
                },
                {
                    "name": "Format Modules",
                    "content": "The various format modules exist to parse and format datetimes. For example,\nDateTime::Format::HTTP parses dates according to the RFC 1123 format:\n\nmy $datetime\n= DateTime::Format::HTTP->parsedatetime(\n'Thu Feb  3 17:03:55 GMT 1994');\n\nprint DateTime::Format::HTTP->formatdatetime($datetime);\n\nMost format modules are suitable for use as a \"formatter\" with a DateTime object.\n\nAll format modules start with DateTime::Format::\n<https://metacpan.org/search?q=datetime%3A%3Aformat>.\n"
                },
                {
                    "name": "Calendar Modules",
                    "content": "There are a number of modules on CPAN that implement non-Gregorian calendars, such as the\nChinese, Mayan, and Julian calendars.\n\nAll calendar modules start with DateTime::Calendar::\n<https://metacpan.org/search?q=datetime%3A%3Acalendar>.\n"
                },
                {
                    "name": "Event Modules",
                    "content": "There are a number of modules that calculate the dates for events, such as Easter, Sunrise, etc.\n\nAll event modules start with DateTime::Event::\n<https://metacpan.org/search?q=datetime%3A%3Aevent>.\n"
                },
                {
                    "name": "Others",
                    "content": "There are many other modules that work with DateTime, including modules in the DateTimeX\nnamespace <https://metacpan.org/search?q=datetimex> namespace, as well as others.\n\nSee MetaCPAN <https://metacpan.org/search?q=datetime> for more modules.\n"
                }
            ]
        },
        "KNOWN BUGS": {
            "content": "The tests in 20infinite.t seem to fail on some machines, particularly on Win32. This appears to\nbe related to Perl's internal handling of IEEE infinity and NaN, and seems to be highly\nplatform/compiler/phase of moon dependent.\n\nIf you don't plan to use infinite datetimes you can probably ignore this. This will be fixed\n(perhaps) in future versions.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "A Date with Perl <http://presentations.houseabsolute.com/a-date-with-perl/> - a talk I've given\nat a few YAPCs.\n\ndatetime@perl.org mailing list <http://lists.perl.org/list/datetime.html>\n",
            "subsections": []
        },
        "SUPPORT": {
            "content": "Bugs may be submitted at <https://github.com/houseabsolute/DateTime.pm/issues>.\n\nThere is a mailing list available for users of this distribution, <mailto:datetime@perl.org>.\n",
            "subsections": []
        },
        "SOURCE": {
            "content": "The source code repository for DateTime can be found at\n<https://github.com/houseabsolute/DateTime.pm>.\n",
            "subsections": []
        },
        "DONATIONS": {
            "content": "If you'd like to thank me for the work I've done on this module, please consider making a\n\"donation\" to me via PayPal. I spend a lot of free time creating free software, and would\nappreciate any support you'd care to offer.\n\nPlease note that I am not suggesting that you must do this in order for me to continue working\non this particular software. I will continue to do so, inasmuch as I have in the past, for as\nlong as it interests me.\n\nSimilarly, a donation made in this way will probably not make me work on this software much\nmore, unless I get so many donations that I can consider working on free software full time\n(let's all have a chuckle at that together).\n\nTo donate, log into PayPal and send money to autarch@urth.org, or use the button at\n<https://www.urth.org/fs-donation.html>.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Dave Rolsky <autarch@urth.org>\n",
            "subsections": []
        },
        "CONTRIBUTORS": {
            "content": "*   Ben Bennett <fiji@limey.net>\n\n*   Christian Hansen <chansen@cpan.org>\n\n*   Daisuke Maki <dmaki@cpan.org>\n\n*   Dan Book <grinnz@gmail.com>\n\n*   Dan Stewart <danielandrewstewart@gmail.com>\n\n*   David Dyck <david.dyck@checksum.com>\n\n*   David E. Wheeler <david@justatheory.com>\n\n*   David Precious <davidp@preshweb.co.uk>\n\n*   Doug Bell <madcityzen@gmail.com>\n\n*   Flávio Soibelmann Glock <fglock@gmail.com>\n\n*   Gianni Ceccarelli <gianni.ceccarelli@broadbean.com>\n\n*   Gregory Oschwald <oschwald@gmail.com>\n\n*   Hauke D <haukex@zero-g.net>\n\n*   Iain Truskett <deceased>\n\n*   Jason McIntosh <jmac@jmac.org>\n\n*   Joshua Hoblitt <jhoblitt@cpan.org>\n\n*   Karen Etheridge <ether@cpan.org>\n\n*   Mark Overmeer <mark@overmeer.net>\n\n*   Michael Conrad <mike@nrdvana.net>\n\n*   Michael R. Davis <mrdvt92@users.noreply.github.com>\n\n*   Mohammad S Anwar <mohammad.anwar@yahoo.com>\n\n*   M Somerville <dracos@users.noreply.github.com>\n\n*   Nick Tonkin <1nickt@users.noreply.github.com>\n\n*   Olaf Alders <olaf@wundersolutions.com>\n\n*   Ovid <curtisovidpoe@yahoo.com>\n\n*   Paul Howarth <paul@city-fan.org>\n\n*   Philippe Bruhat (BooK) <book@cpan.org>\n\n*   philip r brenan <philiprbrenan@gmail.com>\n\n*   Ricardo Signes <rjbs@cpan.org>\n\n*   Richard Bowen <bowen@cpan.org>\n\n*   Ron Hill <rkhill@cpan.org>\n\n*   Sam Kington <github@illuminated.co.uk>\n\n*   viviparous <viviparous@prc>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "This software is Copyright (c) 2003 - 2021 by Dave Rolsky.\n\nThis is free software, licensed under:\n\nThe Artistic License 2.0 (GPL Compatible)\n\nThe full text of the license can be found in the LICENSE file included with this distribution.\n",
            "subsections": []
        }
    },
    "summary": "DateTime - A date and time object for Perl",
    "flags": [],
    "examples": [],
    "see_also": []
}