BSON::Time - BSON type wrapper for date and time
| Use Case | Command | Description |
|---|---|---|
| ๐ Current time | bson_time() | Create BSON::Time for right now |
| ๐ From timestamp | bson_time($secs) | Create from floatingโpoint seconds since epoch |
| โฑ๏ธ Get epoch seconds | $t->epoch | Returns seconds as a float |
| ๐ ISOโ8601 string | $t->as_iso8601 | Formatted like YYYY-MM-DDThh:mm:ss.sssZ |
| ๐ DateTime object | $t->as_datetime | Convert to DateTime |
| ๐ DateTime::Tiny | $t->as_datetime_tiny | Convert to DateTime::Tiny |
| ๐ฅญ Mango::BSON::Time | $t->as_mango_time | Convert for Mango driver |
| โ Time::Moment | $t->as_time_moment | Convert to Time::Moment |
| ๐ค JSON serialisation | $t->TO_JSON | ISOโ8601 or extended JSON (respects env vars) |
| โ Numification / stringification | 0+$t or "$t" | Returns epoch seconds (float) |
version v1.12.2
use BSON::Types ':all';
bson_time(); # now
bson_time( $secs ); # floating point seconds since epoch
This module provides a BSON type wrapper for a 64โbit dateโtime value in the form of milliseconds since the Unix epoch (UTC only).
On a Perl without 64โbit integer support, the value must be a Math::BigInt object.
A integer representing milliseconds since the Unix epoch. The default is 0.
epoch โ Returns the number of seconds since the epoch (i.e. a floatingโpoint value).as_iso8601 โ Returns the value as an ISOโ8601 formatted string of the form YYYY-MM-DDThh:mm:ss.sssZ. The fractional seconds will be omitted if they are zero.as_datetime โ Loads DateTime and returns the value as a DateTime object.as_datetime_tiny โ Loads DateTime::Tiny and returns the value as a DateTime::Tiny object.as_mango_time โ Loads Mango::BSON::Time and returns the value as a Mango::BSON::Time object.as_time_moment โ Loads Time::Moment and returns the value as a Time::Moment object.TO_JSON โ Returns a string formatted by as_iso8601.BSON_EXTJSON option is true, it will instead be compatible with MongoDBโs extended JSON
<https://github.com/mongodb/specifications/blob/master/source/extended-json.rst> format,
which represents it as a document as follows:{"$date" : { "$numberLong": "22337203685477580" } }BSON_EXTJSON environment variable is true and the BSON_EXTJSON_RELAXED environment
variable is false, returns a hashref compatible with MongoDBโs extended JSON
<https://github.com/mongodb/specifications/blob/master/source/extended-json.rst> format,
which represents it as a document as follows:{"$date" : { "$numberLong": "22337203685477580" } }BSON_EXTJSON and BSON_EXTJSON_RELAXED environment variables are both true, then it
will return a hashref with an ISOโ8601 string for dates after the Unix epoch and before the
year 10,000 and a $numberLong style value otherwise.{"$date" : "2012-12-24T12:15:30.500Z"}
{"$date" : { "$numberLong": "-10000000" } }
Both numification (0+) and stringification ("") are overloaded to return the result of
epoch. Numeric comparison and string comparison are overloaded based on those and fallback
overloading is enabled.
This software is Copyright (c) 2020 by Stefan G. and MongoDB, Inc.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
Generated by phpman v4.9.25-4-g0d844aa · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-07 09:06 @216.73.217.93
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-pro / taotoken.net / www.chedong.com - original format