Support Services

How do I calculate UTC time in ticks?

When implementing Forte Checkout, Secure Web Pay, and SOAP web services, a UTC time (in ticks since 01/01/0001 00:00:00A) may be required for authentication.

Forte provides an API, getUTC, which returns the correct UTC time from Forte’s server. Using this server-side value is preferred and prevents inadvertent expiration errors from client PCs that do not have the correct local time set. 


You can use the following PHP/CURL code sample to fetch the UTC time from the getUTC API:

<?php

    function utc() {

        $curlUTC = curl_init();

        curl_setopt($curlUTC, CURLOPT_URL, 'https://checkout.forte.net/getUTC?callback=?');

        curl_setopt($curlUTC, CURLOPT_BINARYTRANSFER, true);

        curl_setopt($curlUTC, CURLOPT_RETURNTRANSFER, true);


        //getUTC output example: ?(XXXXXXXXXXXX643793); where: XXXXXXXXXXXX643793 is the UTC time.

        $curlData = (curl_exec($curlUTC));

        $positionOfOpeningParenthesis = stripos($curlData,"(");

        $positionOfClosingParenthesis = stripos($curlData,")");

        $utc =  substr($curlData,$positionOfOpeningParenthesis+1,$positionOfClosingParenthesis-2);

        return $utc;

        curl_close($curlUTC);

    }



Alternatively, UTC time in ticks can be computed from seconds using the PHP time() function since 01/01/1970 00:00:00AM UTC. This approach is not suggested for reasons discussed earlier. The following code fragments may be helpful in computing the UTC time.

PHP

$time = time() + 62135596800;
'UTC now ticks= echo ' . $time . '0000000';


PERL

#!/usr/bin/perl
# generate UTC time stamp since 01/01/0001 in tics
my $time = (time + 62135596800) . "0000000";


Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.