obspy.core.utcdatetime.UTCDateTime.replace

UTCDateTime.replace(**kwargs)[source]

Return a new UTCDateTime object with one or more parameters replaced.

Replace is useful for substituting parameters that depend on other parameters (eg hour depends on the current day for meaning). In order to replace independent parameters, such as timestamp, ns, or precision, simply create a new UTCDateTime instance.

The following parameters are supported: year, month, day, julday, hour, minute second, microsecond. Additionally, the keyword ‘strict’ can be set to False to allow hour, minute, and second to exceed normal limits.

Example

  1. Get time of the 15th day of the same month to which a timestamp belongs.

    >>> dt = UTCDateTime(999999999)
    >>> dt2 = dt.replace(day=15)
    >>> print(dt2)
    2001-09-15T01:46:39.000000Z
    
  2. Determine the day of the week 2 months before Guy Fawkes day.

    >>> dt = UTCDateTime('1605-11-05')
    >>> dt.replace(month=9).weekday
    0