How to Parse an Unstructured Date and Time String in Node.JS

Often, we receive notifications and requests for meetings or other time-sensitive events via email, which may take the form of an unstructured time like “tomorrow at 3pm” or “Friday at noon.” You can manually input these events into your calendar, or you can use the following API to create an application that logs the time for you. This API will parse any unstructured, natural language date and time string to return a standardized object.

Image for post
Image for post

To use this API, run this command to install the SDK:

npm install cloudmersive-validate-api-client --save

You can also add this snippet to your package.json:

"dependencies": {
"cloudmersive-validate-api-client": "^1.2.4"
}

Then, you can call the function:

var CloudmersiveValidateApiClient = require('cloudmersive-validate-api-client');
var defaultClient = CloudmersiveValidateApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveValidateApiClient.DateTimeApi();var input = new CloudmersiveValidateApiClient.DateTimeNaturalLanguageParseRequest(); // DateTimeNaturalLanguageParseRequest | Input requestvar callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.dateTimeParseNaturalLanguageDateTime(input, callback);

This will return the parsed date result, year, month, day, hour, minute, second, and day of the week.

You can retrieve the API Key from the Cloudmersive website at no cost and with no commitment. This will provide you with 800 monthly calls across our library of APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store