Please enable JavaScript to view this site.

The manual for the JobRouter developer

Navigation: SDK > Interfaces

DateFormatterInterface

Scroll Prev Top Next More

Constants

 

Constant

Value

Description

FORMAT_WITH_POINT

1

Date format id for d.m.Y

FORMAT_WITH_SLASHES

2

Date format id for d/m/Y

FORMAT_WITH_SLASHES_MONTH_FIRST

3

Date format id for m/d/Y

FORMAT_WITH_HYPHENS

4

Date format id for Y-m-d

Methods

 

Method

Parameters

Parameter description

Return

Description

getFormattedDate

$id: int

[$date: bool|int|string = false]

 

[$fullDateTime: bool = false]

[$isTimestamp: bool = false]

[$timeZone: string = '']

ID of the date format (DateFormatterInterface:FORMAT_WITH_*)

Opional date string or date timestamp; if the value is false, the current timestamp is used  (default: false)

Opional flag whether the time should also be returned  (default: false)

Opional flag whether date is a timestamp  (default: false)

Opional time zone  (default: empty string)

string

Returns a formatted date according to a date id (DateFormatterInterface::FORMAT_WITH_*). If an invalid ID is specified, the method returns the date in the standard format

 

getUnformattedDate

$id: int

$date: string

[$fullDateTime: bool = false]

[$sourceTimeZone: string = '']

[$targetTimeZone: string = '']

ID of the date format (DateFormatterInterface:FORMAT_WITH_*)

Date string

Opional flag whether the time should also be returned (default: false)

Opional source time zone (default: empty string)

Opional target time zone (default: empty string)

string

Returns a date in the standard format YYYY-MM-DD.

Example

 

<?php

 

use JobRouter\Sdk\DateFormatterInterface;

 

return function (DateFormatterInterface $jobRouterDateFormatter): void {

    echo '<h1 style="color: #fc0">JobRouter SDK Date Formatter Interface example!</h1>';

 

    try {

        echo '<pre>Formatted Date (FORMAT_WITH_POINT): ' . print_r(

                $jobRouterDateFormatter->getFormattedDate(

                    DateFormatterInterface::FORMAT_WITH_POINT,

                    fullDateTime: true,

                    isTimestamp: true,

                ),

                true,

            ) . '</pre>';

 

        echo '<pre>Formatted Date (FORMAT_WITH_SLASHES): ' . print_r(

                $jobRouterDateFormatter->getFormattedDate(

                    DateFormatterInterface::FORMAT_WITH_SLASHES,

                    fullDateTime: true,

                    isTimestamp: true,

                ),

                true,

            ) . '</pre>';

 

        echo '<pre>Formatted Date (FORMAT_WITH_SLASHES_MONTH_FIRST): ' . print_r(

                $jobRouterDateFormatter->getFormattedDate(

                    DateFormatterInterface::FORMAT_WITH_SLASHES_MONTH_FIRST,

                    fullDateTime: true,

                    isTimestamp: true,

                ),

                true,

            ) . '</pre>';

 

        echo '<pre>Formatted Date (FORMAT_WITH_HYPHENS): ' . print_r(

                $jobRouterDateFormatter->getFormattedDate(

                    DateFormatterInterface::FORMAT_WITH_HYPHENS,

                    fullDateTime: true,

                    isTimestamp: true,

                ),

                true,

            ) . '</pre>';

 

        echo '<br />';

        echo '<pre>Unformatted Date (FORMAT_WITH_POINT): ' . print_r(

                $jobRouterDateFormatter->getUnformattedDate(

                    DateFormatterInterface::FORMAT_WITH_POINT,

                    $jobRouterDateFormatter->getFormattedDate(

                        DateFormatterInterface::FORMAT_WITH_POINT,

                        fullDateTime: true,

                        isTimestamp: true,

                    ),

                ),

                true,

            ) . '</pre>';

    } catch (\RuntimeException $e) {

        echo '<h3 style="color: #f44;">Error!</h3>';

        echo '<p style="color: #f44;">Message: ' . $e->getMessage() . '</p>';

    }

};

 

Response:

 

JobRouter SDK Date Formatter Interface example!

 

Formatted Date (FORMAT_WITH_POINT): 24.12.2024 18:00:00

Formatted Date (FORMAT_WITH_SLASHES): 24/12/2024 18:00:00

Formatted Date (FORMAT_WITH_SLASHES_MONTH_FIRST): 12/24/2024 18:00:00

Formatted Date (FORMAT_WITH_HYPHENS): 2024-12-24 18:00:00

 

Unformatted Date (FORMAT_WITH_POINT): 2024-11-24