Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A simple utility for precise-dateing functions and classes.

License

NotificationsYou must be signed in to change notification settings

googleapis/nodejs-precise-date

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Google Cloud Platform logo

@google-cloud/precise-date

A simple utility for precise-dateing functions and classes.

Installing the package

It's unlikely you will need to install this package directly, as it will beinstalled as a dependency when you install other@google-cloud packages.

$ npm install --save @google-cloud/precise-date

Using the package

PreciseDate extends the nativeDate object, so you can use it in place ofthat or when you need nanosecond precision.

const{PreciseDate}=require('@google-cloud/precise-date');constdate=newPreciseDate('1547253035381101032');date.toISOString();// => 2019-01-12T00:30:35.381101032Zdate.toFullTimeString();// => '1547253035381101032'

API

PreciseDate([time])

Returns a newdate instance.

time

Type:stringBigIntObject<string, number>[number, number]

// from a full ISO stringdate=newPreciseDate('2019-02-08T10:34:29.481145231Z');// from a string representing nanosecondsdate=newPreciseDate('1549622069481320032');// from a BigInt representing nanoseconds (requires Node >= 10.7)date=newPreciseDate(1549622069481320032n);// from an object containing `seconds` and `nanos` valuesdate=newPreciseDate({seconds:1549622069,nanos:481320032});// from a tuple representing [seconds, nanos]date=newPreciseDate([1549622069,481320032]);

PreciseDate.parseFull(time)

Similar toDate.parse(), but this accepts the same nanosecond time options as thePreciseDate constructor and returns a string representing the nanoseconds in the specified date according to universal time.

PreciseDate.parseFull('2019-02-08T10:34:29.481145231Z');// => '1549622069481145231'

PreciseDate.fullUTCString(...dateFields)

Similar toDate.UTC(), but also accepts microsecond and nanosecond parameters. Returns a string that represents the number of nanoseconds since January 1, 1970, 00:00:00 UTC.

dateFields

Type:...number

PreciseDate.fullUTCString(2019,1,8,10,34,29,481,145,231);// => '1549622069481145231'

PreciseDate.fullUTC(...dateFields)

LikePreciseDate.fullUTCString() but returns a nativeBigInt instead of a string.Requires Node >= 10.7.

dateFields

Type:...number

PreciseDate.fullUTC(2019,1,8,10,34,29,481,145,231);// => 1549622069481145231n

date

PreciseDate instance.

date.getFullTimeString()

Returns a string of the specified date represented in nanoseconds according to universal time.

date.getFullTime()

Likedate.getFullTimeString() but returns a nativeBigInt instead of a string.Requires Node >= 10.7.

date.getMicroseconds()

Returns the microseconds in the specified date according to universal time.

date.getNanoseconds()

Returns the nanoseconds in the specified date according to universal time.

date.setMicroseconds(microseconds)

Sets the microseconds for a specified date according to universal time. Returns a string representing the nanoseconds in the specified date according to universal time.

microseconds

Type:number

date.setNanoseconds(nanoseconds)

Sets the nanoseconds for a specified date according to universal time. Returns a string representing the nanoseconds in the specified date according to universal time.

nanoseconds

Type:number

date.setFullTime(time)

Sets the time to the number of supplied nanoseconds since January 1, 1970, 00:00:00 UTC. Returns a string representing the nanoseconds in the specified date according to universal time (effectively, the value of the argument).

time

Type:numberstringBigInt

date.toStruct()

Returns an object representing the specified date according to universal time.Refer togoogle.protobuf.Timestamp for more information about this format.

const{seconds, nanos}=date.toStruct();

date.toTuple()

Likedate.toStruct() but returns theseconds andnanos as a tuple.

const[seconds,nanos]=date.toTuple();

Versioning

This library followsSemantic Versioning.

Contributing

Contributions welcome! See theContributing Guide.

License

Apache Version 2.0

SeeLICENSE

About

A simple utility for precise-dateing functions and classes.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors18


[8]ページ先頭

©2009-2025 Movatter.jp