https://github.com/divineomega/php-dot-net-ticks
⏱ PHP .NET Ticks helps you convert .NET ticks, a form of precise time measurement used by the .NET DateTime object.
https://github.com/divineomega/php-dot-net-ticks
date datetime dot-net dotnet php php-library time
Last synced: 8 months ago
JSON representation
⏱ PHP .NET Ticks helps you convert .NET ticks, a form of precise time measurement used by the .NET DateTime object.
- Host: GitHub
- URL: https://github.com/divineomega/php-dot-net-ticks
- Owner: DivineOmega
- License: lgpl-3.0
- Created: 2018-02-07T14:00:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-09T16:54:12.000Z (over 8 years ago)
- Last Synced: 2025-02-28T06:04:31.871Z (over 1 year ago)
- Topics: date, datetime, dot-net, dotnet, php, php-library, time
- Language: PHP
- Homepage:
- Size: 27.3 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ⏱ PHP .NET Ticks
[](https://travis-ci.org/DivineOmega/php-dot-net-ticks)
[](https://coveralls.io/github/DivineOmega/php-dot-net-ticks?branch=master)
[](https://styleci.io/repos/120622320)
This package helps PHP developers work with and convert .NET ticks, a form of precise time measurement used by the .NET `DateTime` object.
## Features
You can use this library to do the following, and more.
* Convert ticks to timestamp
* Convert ticks to `DateTime` object
* Convert ticks to `Carbon` date object
* Get the current time in ticks
* Convert timestamp to ticks
## What are .NET ticks?
> A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second.
> The value of this property [`DateTime.Ticks`] represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 (0:00:00 UTC on January 1, 0001, in the Gregorian calendar), which represents DateTime.MinValue. It does not include the number of ticks that are attributable to leap seconds.
*Source: [.NET API Reference: DateTime.Tick Property](https://msdn.microsoft.com/en-us/library/system.datetime.ticks(v=vs.110).aspx)*
## Installation
The PHP .NET Ticks package can be easily installed using Composer. Just run the following command from the root of your project.
```
composer require divineomega/php-dot-net-ticks
```
If you have never used the Composer dependency manager before, head to the [Composer website](https://getcomposer.org/) for more information on how to get started.
## Usage
First you need to create a new `Ticks` object. This can be done in several ways.
```php
use DivineOmega\DotNetTicks\Ticks;
// Current time
$ticks = new Ticks();
// Specific time in ticks
$ticks = new Ticks(636536021491253348);
// From timestamp
$ticks = Ticks::createFromTimestamp(1518005349);
```
You can then call methods on the `Ticks` object to retrieve or convert as necessary.
```php
$ticks = $ticks->ticks(); // Ticks
$time = $ticks->timestamp(); // UNIX timstamp
$dateTime = $ticks->dateTime(); // PHP DateTime object
$carbon = $ticks->carbon(); // Carbon date object
```
If you wish, you can combine these two steps into one line, as shown in the examples below.
```php
// Get current time in ticks
$nowInTicks = (new Ticks())->ticks();
// Convert ticks to timestamp
$timestamp = (new Ticks(636536021491253348))->timestamp();
// Convert timestamp to ticks
$ticks = Ticks::createFromTimestamp(1518005349)->ticks();
```