An Industrial IOT Platform

Working with Dates

Time is relative!

One of the complexities of working with Date and Time in software development is to keep track of the time zone to which the time is referring to. Date and Time are usually stored/sent/received as strings in the typical format:

'2020-08-13 14:30:00'

The problem is that this string does not mention the time zone used. 

The Solution => The ECMA / ISO8601 Format.

 

The ECMA/ISO8601 Format

ISO8601 is a date and time format that provides date, time and it's timezone as a single stirng. ECMA is an interoperability standard which allows computer languages to understand each other. ECMA adopts ISO8601 date time format. ECMA is popular because it is adopted by almost all Javascript Compilers and Web Browsers.

In ECMA, The date and time will be in the following format:

YYYY-MM-DDTHH:mm:ss.sssZ

Example:
2020-08-13T06:38:10.032Z


The T in the middle means Time
The Z at the end means the timezone is UTC
(These 2 Letters are COMPULSORY for ECMA Compliance)

Open-Plant Web APIs accept & return ECMA / ISO8601

All Open-Plant WebAPIs accept date time input in in ECMA / ISO8601 (which is in UTC)

Example WebAPI Call:
 https://localhost:33170/api/sample?tagid=random1.value×tamp=2020-08-13T13:17:13.850Z
All Open-Plant WebAPIs return JSON objects with date time properties in ECMA / ISO8601

Example WebAPI JSON Return:
{
  "data": {
    "TSUTC": "2020-08-13T07:00:57.7217364Z",
    "Value": null,
    "IsError": false
  }
}

ECMA/ISO8601 ensures compatibility with Javascript

By using ECMA / ISO8601, compatibility with Javascript is ensured. Coding in Javascript becomes easy. Javascript powers angular, react and all popular frontend frameworks.

To convert a Javascript date object to ISO8601 string use:
	
//Use the .toISOString to convert Javascript Date to ISO8601 String
//The function will take note of your current time zone to convert to UTC
var CurrentDate = new Date().toISOString();
document.write(CurrentDate);
    
//Result:
//2020-08-13T07:57:56.113Z



//To create a data object from an ECMA ISO8601 string:
var MyDate = new Date('2020-08-10T07:57:56.113Z');


Open-Plant is a revolutionary Industrial IOT Platform software, used to create and deploy Industrial IT apps/solutions. It is an all-encompassing solution offering both back-end and front-end components i.e. the full stack. From our user's experience, creating and deploying Industrial IT apps became 10x faster and 10x less cost. We serve the mining, energy, oil & gas, construction and manufacturing industry. 

OPEN-PLANT PTY LTD

Perth, Australia

EMAIL

info@open-plant.com
homedownloadenvelope