Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Time#xmlschema
(?::Integer fraction_digits) -> ::String
xmlschema(fraction_digits=0)
lib/time.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/time.rb, line 770
def xmlschema(fraction_digits=0)
fraction_digits = fraction_digits.to_i
s = strftime("%FT%T")
if fraction_digits > 0
s << strftime(".%#{fraction_digits}N")
end
s << (utc? ? 'Z' : strftime("%:z"))
end
Returns a string which represents the time as a dateTime defined by XML Schema:
CCYY-MM-DDThh:mm:ssTZD CCYY-MM-DDThh:mm:ss.sssTZD
where TZD is Z or [+-]hh:mm.
If self is a UTC time, Z is used as TZD. [+-]hh:mm is used otherwise.
fraction_digits specifies a number of digits to use for fractional seconds. Its default value is 0.
Example
require 'time' t = Time.now t.iso8601 # => "2011-10-05T22:26:12-04:00"
You must require ‘time’ to use this method.
Ruby version changes
-
3.4
-
Time#xmlschema, and itsTime#iso8601alias have been moved into the coreTimeclass while previously it was an extension provided by thetimegem. [Feature #20707]
-