# perldoc > BSON::Time

---
type: CommandReference
command: BSON::Time
mode: perldoc
section: ""
source: perldoc
---

## Quick Reference
- `bson_time()` — get current time as `BSON::Time`
- `bson_time(1234567890.5)` — from seconds since Unix epoch
- `BSON::Time->new(value => 1514764800000)` — from milliseconds
- `$obj->epoch` — floating-point seconds since epoch
- `$obj->as_iso8601` — ISO 8601 string (e.g., `2018-01-01T00:00:00Z`)
- `$obj->as_datetime` — convert to `DateTime` object
- `$obj->as_time_moment` — convert to `Time::Moment` object
- `"$obj"` — stringification yields epoch seconds

## Name
BSON type wrapper for a 64-bit date-time value (milliseconds since Unix epoch, UTC only).

## Synopsis
perl
use BSON::Types ':all';

bson_time();        # now
bson_time( $secs ); # floating point seconds since epoch
## Options
- `value` — integer (or `Math::BigInt`) milliseconds since Unix epoch (default `0`)
- `epoch` — method: returns floating-point seconds since epoch
- `as_iso8601` — method: returns `YYYY-MM-DDThh:mm:ss.sssZ` string (fractional seconds omitted if zero)
- `as_datetime` — method: returns a `DateTime` object
- `as_datetime_tiny` — method: returns a `DateTime::Tiny` object
- `as_mango_time` — method: returns a `Mango::BSON::Time` object
- `as_time_moment` — method: returns a `Time::Moment` object
- `TO_JSON` — method: returns ISO-8601 string; if `BSON_EXTJSON` env is true, returns MongoDB extended JSON (hashref with `$date` containing ISO string or `$numberLong`). With `BSON_EXTJSON_RELAXED`, uses relaxed format.
- Overloading — numify (`0+`) and stringify (`""`) return `epoch`; numeric and string comparisons are supported

## Examples
perl
use BSON::Time;

# from epoch seconds
my $t = bson_time(1514764800);         # 2018-01-01T00:00:00Z
say $t->as_iso8601;                     # 2018-01-01T00:00:00Z
say $t->epoch;                          # 1514764800

# current time
my $now = bson_time();
my $dt = $now->as_datetime;            # DateTime object
## See Also
- [BSON](http://localhost/phpMan.php/perldoc/BSON/markdown)
- [BSON::Types](http://localhost/phpMan.php/perldoc/BSON%3A%3ATypes/markdown)
- [DateTime](http://localhost/phpMan.php/perldoc/DateTime/markdown)
- [DateTime::Tiny](http://localhost/phpMan.php/perldoc/DateTime%3A%3ATiny/markdown)
- [Time::Moment](http://localhost/phpMan.php/perldoc/Time%3A%3AMoment/markdown)
- [Mango::BSON::Time](http://localhost/phpMan.php/perldoc/Mango%3A%3ABSON%3A%3ATime/markdown)