# man > BSON::Time

---
type: CommandReference
command: BSON::Time
mode: perldoc
section: 3pm
source: perldoc
---

## Quick Reference
- `bson_time()` — current time  
- `bson_time($secs)` — time from floating-point seconds since epoch  
- `$time->epoch` — seconds since epoch as float  
- `$time->as_iso8601` — ISO‑8601 string, fractional seconds omitted if zero  
- `$time->as_datetime` — [DateTime](https://metacpan.org/pod/DateTime) object  
- `$time->as_time_moment` — [Time::Moment](https://metacpan.org/pod/Time::Moment) object  
- `0+$time` or `"$time"` — numification/stringification use `epoch`  
- `$time->TO_JSON` — JSON serialisation (extended JSON via environment flags)

## Name
BSON type wrapper for date and time

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

bson_time();          # now (milliseconds since Unix epoch)
bson_time( $secs );   # floating-point seconds since epoch
## Options
### Attributes
- `value` — integer milliseconds since Unix epoch, default 0; on Perls without 64‑bit integers the value must be a [Math::BigInt](https://metacpan.org/pod/Math::BigInt)

### Methods
- `epoch()` — floating-point seconds since the epoch  
- `as_iso8601()` — ISO‑8601 string `YYYY-MM-DDThh:mm:ss.sssZ`; fractional seconds omitted if zero  
- `as_datetime()` — loads [DateTime](https://metacpan.org/pod/DateTime), returns a DateTime object  
- `as_datetime_tiny()` — loads [DateTime::Tiny](https://metacpan.org/pod/DateTime::Tiny), returns a DateTime::Tiny object  
- `as_mango_time()` — loads [Mango::BSON::Time](https://metacpan.org/pod/Mango::BSON::Time), returns that object  
- `as_time_moment()` — loads [Time::Moment](https://metacpan.org/pod/Time::Moment), returns a Time::Moment object  
- `TO_JSON()`  
  - by default returns an ISO‑8601 string  
  - if `BSON_EXTJSON` is true and `BSON_EXTJSON_RELAXED` is false: returns MongoDB extended JSON document `{"$date" : {"$numberLong": "<millis>"}}`  
  - if both `BSON_EXTJSON` and `BSON_EXTJSON_RELAXED` are true: returns relaxed form — ISO‑8601 string for dates after epoch and before year 10 000, otherwise `$numberLong`

### Overloading
- Numification (`0+`) and stringification (`""`) both return `epoch`  
- Numeric and string comparisons overloaded accordingly; fallback enabled

## See Also
- [BSON](https://metacpan.org/pod/BSON)  
- [BSON::Types](https://metacpan.org/pod/BSON::Types)  
- [DateTime](https://metacpan.org/pod/DateTime)  
- [DateTime::Tiny](https://metacpan.org/pod/DateTime::Tiny)  
- [Time::Moment](https://metacpan.org/pod/Time::Moment)  
- [Mango::BSON::Time](https://metacpan.org/pod/Mango::BSON::Time)  
- [Math::BigInt](https://metacpan.org/pod/Math::BigInt)  
- MongoDB extended JSON specification: [https://github.com/mongodb/specifications/blob/master/source/extended-json.rst](https://github.com/mongodb/specifications/blob/master/source/extended-json.rst)