#### [Abblix\.Jwt](https://www.abblix.com/docs/api/abblix-jwt 'index')
### [Abblix\.Jwt](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt 'Abblix\.Jwt')

## NumericDateExtensions Class

Reads and writes the NumericDate members of a JWT \(RFC 7519 section 2\): seconds since the epoch\.

```csharp
public static class NumericDateExtensions
```

Inheritance [System\.Object](https://learn.microsoft.com/en-us/dotnet/api/system.object 'System\.Object') → NumericDateExtensions
### Methods

## NumericDateExtensions\.GetUnixTimeSeconds\(this JsonObject, string\) Method {#Abblix.Jwt.NumericDateExtensions.GetUnixTimeSeconds(thisSystem.Text.Json.Nodes.JsonObject,string)}

Retrieves a [System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset') value from a [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') based on
a property stored as Unix time seconds\.

```csharp
public static System.Nullable<System.DateTimeOffset> GetUnixTimeSeconds(this System.Text.Json.Nodes.JsonObject json, string name);
```
#### Parameters

###### `json` [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') {#Abblix.Jwt.NumericDateExtensions.GetUnixTimeSeconds(thisSystem.Text.Json.Nodes.JsonObject,string).json}

The [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') from which to retrieve the date/time value\.

###### `name` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Jwt.NumericDateExtensions.GetUnixTimeSeconds(thisSystem.Text.Json.Nodes.JsonObject,string).name}

The property name containing the Unix time seconds\.

#### Returns
[System\.Nullable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1')[System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1')  
A nullable [System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset') representing the date and time of the specified property,
or `null` if the property is not present\.

#### Exceptions

[System\.InvalidOperationException](https://learn.microsoft.com/en-us/dotnet/api/system.invalidoperationexception 'System\.InvalidOperationException')  
The value is not a number\.

[System\.Text\.Json\.JsonException](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonexception 'System\.Text\.Json\.JsonException')  
The value is a JSON kind no number can be read from\.

[System\.ArgumentOutOfRangeException](https://learn.microsoft.com/en-us/dotnet/api/system.argumentoutofrangeexception 'System\.ArgumentOutOfRangeException')  
The number is outside the range a date can hold\.

### Remarks
Unix time seconds are widely used for representing date and time in JSON objects, especially in JWTs\.
This method simplifies retrieving such values by converting them directly to [System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset')\.
A value that is present and cannot be read THROWS rather than answering null: a caller judging a token
somebody else wrote reads through [TryReadTimestamp\(string, Nullable&lt;DateTimeOffset&gt;, string\)](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.JsonWebTokenPayload#Abblix.Jwt.JsonWebTokenPayload.TryReadTimestamp(string,System.Nullable_System.DateTimeOffset_,string) 'Abblix\.Jwt\.JsonWebTokenPayload\.TryReadTimestamp\(string, System\.Nullable\<System\.DateTimeOffset\>, string\)') instead, which
names the claim in a refusal\.

## NumericDateExtensions\.SetUnixTimeSeconds\(this JsonObject, string, Nullable\<DateTimeOffset\>\) Method {#Abblix.Jwt.NumericDateExtensions.SetUnixTimeSeconds(thisSystem.Text.Json.Nodes.JsonObject,string,System.Nullable_System.DateTimeOffset_)}

Sets a [System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset') value in a [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject'), stored as Unix time seconds\.

```csharp
public static void SetUnixTimeSeconds(this System.Text.Json.Nodes.JsonObject json, string name, System.Nullable<System.DateTimeOffset> value);
```
#### Parameters

###### `json` [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') {#Abblix.Jwt.NumericDateExtensions.SetUnixTimeSeconds(thisSystem.Text.Json.Nodes.JsonObject,string,System.Nullable_System.DateTimeOffset_).json}

The [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') to modify\.

###### `name` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Jwt.NumericDateExtensions.SetUnixTimeSeconds(thisSystem.Text.Json.Nodes.JsonObject,string,System.Nullable_System.DateTimeOffset_).name}

The property name under which to store the Unix time seconds\.

###### `value` [System\.Nullable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1')[System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1') {#Abblix.Jwt.NumericDateExtensions.SetUnixTimeSeconds(thisSystem.Text.Json.Nodes.JsonObject,string,System.Nullable_System.DateTimeOffset_).value}

The [System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset') value to set\. If `null`,
                the property will be removed from the JSON object\.

### Remarks
Storing dates as Unix time seconds is a common practice in JWTs and other JSON structures\.
This method facilitates setting such values by converting [System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset') to Unix time seconds\.
