Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Unicode C Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Unicode C) JSON Date Parsing

Demonstrates how to parse date/time strings from JSON.

Note: This example uses the DtOf and DateOf methods introduced in Chilkat v9.5.0.73

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Solaris C/C++

MinGW C/C++

#include <C_CkJsonObjectW.h>
#include <C_CkDateTimeW.h>
#include <C_CkDtObjW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkJsonObjectW json;
    HCkDateTimeW dateTime;
    HCkDtObjW dt;
    BOOL getAsLocal;



    json = CkJsonObjectW_Create();
    CkJsonObjectW_putEmitCompact(json,FALSE);

    // First, let's create JSON containing some date/time strings.
    CkJsonObjectW_UpdateString(json,L"test.timestamp",L"2018-01-30T20:35:00Z");
    CkJsonObjectW_UpdateString(json,L"test.rfc822",L"Tue, 24 Apr 2018 08:47:03 -0500");
    CkJsonObjectW_UpdateString(json,L"test.dateStrings[0]",L"2018-01-30T20:35:00Z");
    CkJsonObjectW_UpdateString(json,L"test.dateStrings[1]",L"Tue, 24 Apr 2018 08:47:03 -0500");
    CkJsonObjectW_UpdateNumber(json,L"test.StartLoggingTime",L"1446834998.695");
    CkJsonObjectW_UpdateNumber(json,L"test.Expiration",L"1442877512.0");
    CkJsonObjectW_UpdateInt(json,L"test.StartTime",1518867432);

    wprintf(L"%s\n",CkJsonObjectW_emit(json));

    // We've built the following JSON:

    // {
    //   "test": {
    //     "timestamp": "2018-01-30T20:35:00Z",
    //     "rfc822": "Tue, 24 Apr 2018 08:47:03 -0500",
    //     "dateStrings": [
    //       "2018-01-30T20:35:00Z",
    //       "Tue, 24 Apr 2018 08:47:03 -0500"
    //     ],
    //     "StartLoggingTime": 1446834998.695,
    //     "Expiration": 1442877512.0,
    //     "StartTime": 1518867432
    //   }
    // }

    // Use the DateOf and DtOf methods to load Chilkat date/time objects with the date/time values.
    // The CkDateTime object is primarily for loading a date/time from numerous formats, and then getting
    // the date/time in various formats.  Thus, it's primarly for date/time format conversion.
    // The DtObj object holds a date/time where the individual components (day, month, year, hour, minutes, etc.) are 
    // immediately accessible as integers.
    dateTime = CkDateTimeW_Create();
    dt = CkDtObjW_Create();
    getAsLocal = FALSE;

    // Load the date/time at test.timestamp into the dateTime object.
    success = CkJsonObjectW_DateOf(json,L"test.timestamp",dateTime);
    wprintf(L"%s\n",CkDateTimeW_getAsTimestamp(dateTime,getAsLocal));
    wprintf(L"%d\n",CkDateTimeW_GetAsUnixTime(dateTime,FALSE));
    wprintf(L"%s\n",CkDateTimeW_getAsRfc822(dateTime,getAsLocal));

    success = CkJsonObjectW_DateOf(json,L"test.rfc822",dateTime);
    wprintf(L"%s\n",CkDateTimeW_getAsTimestamp(dateTime,getAsLocal));

    CkJsonObjectW_putI(json,0);
    success = CkJsonObjectW_DateOf(json,L"test.dateStrings[i]",dateTime);
    wprintf(L"%s\n",CkDateTimeW_getAsTimestamp(dateTime,getAsLocal));

    CkJsonObjectW_putI(json,1);
    success = CkJsonObjectW_DateOf(json,L"test.dateStrings[i]",dateTime);
    wprintf(L"%s\n",CkDateTimeW_getAsTimestamp(dateTime,getAsLocal));

    success = CkJsonObjectW_DateOf(json,L"test.StartLoggingTime",dateTime);
    wprintf(L"%s\n",CkDateTimeW_getAsTimestamp(dateTime,getAsLocal));

    success = CkJsonObjectW_DateOf(json,L"test.Expiration",dateTime);
    wprintf(L"%s\n",CkDateTimeW_getAsTimestamp(dateTime,getAsLocal));

    success = CkJsonObjectW_DateOf(json,L"test.StartTime",dateTime);
    wprintf(L"%s\n",CkDateTimeW_getAsTimestamp(dateTime,getAsLocal));

    // Output so far:

    // 	2018-01-30T20:35:00Z
    // 	1517344500
    // 	Tue, 30 Jan 2018 20:35:00 GMT
    // 	2018-04-24T13:47:03Z
    // 	2018-01-30T20:35:00Z
    // 	2018-04-24T13:47:03Z
    // 	2015-11-07T00:36:38Z
    // 	2015-09-22T04:18:32Z
    // 	2018-02-17T17:37:12Z

    // Now load the date/time strings into the dt object:
    success = CkJsonObjectW_DtOf(json,L"test.timestamp",getAsLocal,dt);
    wprintf(L"month=%d, day=%d, year=%d, hour=%d, minute=%d\n",CkDtObjW_getMonth(dt),CkDtObjW_getDay(dt),CkDtObjW_getYear(dt),CkDtObjW_getHour(dt)
        ,CkDtObjW_getMinute(dt));

    success = CkJsonObjectW_DtOf(json,L"test.rfc822",getAsLocal,dt);
    wprintf(L"month=%d, day=%d, year=%d, hour=%d, minute=%d\n",CkDtObjW_getMonth(dt),CkDtObjW_getDay(dt),CkDtObjW_getYear(dt),CkDtObjW_getHour(dt)
        ,CkDtObjW_getMinute(dt));

    CkJsonObjectW_putI(json,0);
    success = CkJsonObjectW_DtOf(json,L"test.dateStrings[i]",getAsLocal,dt);
    wprintf(L"month=%d, day=%d, year=%d, hour=%d, minute=%d\n",CkDtObjW_getMonth(dt),CkDtObjW_getDay(dt),CkDtObjW_getYear(dt),CkDtObjW_getHour(dt)
        ,CkDtObjW_getMinute(dt));

    CkJsonObjectW_putI(json,1);
    success = CkJsonObjectW_DtOf(json,L"test.dateStrings[i]",getAsLocal,dt);
    wprintf(L"month=%d, day=%d, year=%d, hour=%d, minute=%d\n",CkDtObjW_getMonth(dt),CkDtObjW_getDay(dt),CkDtObjW_getYear(dt),CkDtObjW_getHour(dt)
        ,CkDtObjW_getMinute(dt));

    success = CkJsonObjectW_DtOf(json,L"test.StartLoggingTime",getAsLocal,dt);
    wprintf(L"month=%d, day=%d, year=%d, hour=%d, minute=%d\n",CkDtObjW_getMonth(dt),CkDtObjW_getDay(dt),CkDtObjW_getYear(dt),CkDtObjW_getHour(dt)
        ,CkDtObjW_getMinute(dt));

    success = CkJsonObjectW_DtOf(json,L"test.Expiration",getAsLocal,dt);
    wprintf(L"month=%d, day=%d, year=%d, hour=%d, minute=%d\n",CkDtObjW_getMonth(dt),CkDtObjW_getDay(dt),CkDtObjW_getYear(dt),CkDtObjW_getHour(dt)
        ,CkDtObjW_getMinute(dt));

    success = CkJsonObjectW_DtOf(json,L"test.StartTime",getAsLocal,dt);
    wprintf(L"month=%d, day=%d, year=%d, hour=%d, minute=%d\n",CkDtObjW_getMonth(dt),CkDtObjW_getDay(dt),CkDtObjW_getYear(dt),CkDtObjW_getHour(dt)
        ,CkDtObjW_getMinute(dt));

    // Output:

    // month=1, day=30, year=2018, hour=20, minute=35
    // month=4, day=24, year=2018, hour=13, minute=47
    // month=1, day=30, year=2018, hour=20, minute=35
    // month=4, day=24, year=2018, hour=13, minute=47
    // month=11, day=6, year=2015, hour=18, minute=36
    // month=9, day=21, year=2015, hour=23, minute=18
    // month=2, day=17, year=2018, hour=11, minute=37


    CkJsonObjectW_Dispose(json);
    CkDateTimeW_Dispose(dateTime);
    CkDtObjW_Dispose(dt);

    }

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.