public static ToDateTimeFromMillisecondsSinceEpoch ( long millisecondsSinceEpoch ) : System.DateTime | ||
millisecondsSinceEpoch | long | The number of milliseconds since Unix epoch. |
리턴 | System.DateTime |
/// <summary> /// Initializes a new instance of the BsonDateTime class. /// </summary> /// <param name="millisecondsSinceEpoch">Milliseconds since Unix Epoch.</param> public BsonDateTime(long millisecondsSinceEpoch) : base(BsonType.DateTime) { this.millisecondsSinceEpoch = millisecondsSinceEpoch; if (millisecondsSinceEpoch >= BsonConstants.DateTimeMinValueMillisecondsSinceEpoch && millisecondsSinceEpoch <= BsonConstants.DateTimeMaxValueMillisecondsSinceEpoch) { this.value = BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(millisecondsSinceEpoch); } }
/// <summary> /// Returns a string representation of the value. /// </summary> /// <returns>A string representation of the value.</returns> public override string ToString() { if (IsValidDateTime) { return(BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(_millisecondsSinceEpoch).ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFFK")); } else { return(JsonConvert.ToString(_millisecondsSinceEpoch)); } }
/// <summary> /// Converts this BsonValue to a DateTime in UTC. /// </summary> /// <returns>A DateTime.</returns> public override DateTime ToUniversalTime() { return(BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(_millisecondsSinceEpoch)); }
/// <summary> /// Converts the BsonDateTime value to a .NET DateTime value in the local timezone. /// </summary> /// <returns>A DateTime in the local timezone.</returns> public DateTime ToLocalTime() { var utcDateTime = BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(_millisecondsSinceEpoch); return(BsonUtils.ToLocalTime(utcDateTime, DateTimeKind.Local)); }