Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) How to Parse a TimeStamp (such as 2016-11-11T14:32:17.0908971Z)Timestamps are frequently used in REST API responses. This example demonstrates how to parse a timestamp string to get at the date/time components in the local timezone or in the GMT/UTC timezone.
#include <CkDateTime.h> #include <CkDtObj.h> void ChilkatSample(void) { CkString strOut; // Let's say we have a timestamp string such as 2016-11-11T14:32:17.0908971Z const char *strTimestamp = "2016-11-11T14:32:17.0908971Z"; CkDateTime dateTime; dateTime.SetFromTimestamp(strTimestamp); // Get a DtObj in the local timezone. bool bLocalTimezone = true; CkDtObj *dt = dateTime.GetDtObj(bLocalTimezone); // Get the individual date/time components strOut.append("-- Local Time --"); strOut.append("\r\n"); strOut.append("Year: "); strOut.appendInt(dt->get_Year()); strOut.append("\r\n"); strOut.append("Month: "); strOut.appendInt(dt->get_Month()); strOut.append("\r\n"); strOut.append("Day: "); strOut.appendInt(dt->get_Day()); strOut.append("\r\n"); strOut.append("Hour: "); strOut.appendInt(dt->get_Hour()); strOut.append("\r\n"); strOut.append("Minutes: "); strOut.appendInt(dt->get_Minute()); strOut.append("\r\n"); strOut.append("Seconds: "); strOut.appendInt(dt->get_Second()); strOut.append("\r\n"); delete dt; // Get a DtObj in the GMT/UTC timezone. bLocalTimezone = false; dt = dateTime.GetDtObj(bLocalTimezone); // Get the individual date/time components strOut.append("-- UTC Time --"); strOut.append("\r\n"); strOut.append("Year: "); strOut.appendInt(dt->get_Year()); strOut.append("\r\n"); strOut.append("Month: "); strOut.appendInt(dt->get_Month()); strOut.append("\r\n"); strOut.append("Day: "); strOut.appendInt(dt->get_Day()); strOut.append("\r\n"); strOut.append("Hour: "); strOut.appendInt(dt->get_Hour()); strOut.append("\r\n"); strOut.append("Minutes: "); strOut.appendInt(dt->get_Minute()); strOut.append("\r\n"); strOut.append("Seconds: "); strOut.appendInt(dt->get_Second()); strOut.append("\r\n"); delete dt; SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.