Get Current Date/time
I am trying to build a connector which needs the call to include the date and time in the header..
Date / Time (x-mc-date)
The x-mc-date header must be created in the following format:
Tue, 24 Nov 2015 12:50:11 GMT
Any ideas how I can get the current date and time and then also in this format?
Thanks
Best Answer
-
Here's a little more formatting to get the result you need:
var options = {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false
}
today = new Date();var date = today.toLocaleDateString("en-AU", options) + ' GMT';
// Replace period with nothing
var date1 = date.replace(".", "");// Replace all instances of a comma with nothing
var date2 = date1.replace(/,/g, "");// Re-add the comma after the weekday
var final = date2.substring(0, 3) + ', ' + date2.substring(4);
console.log(final);
Cheers
Eric
1
Answers
-
Hello @Simon_King ,
The format to do that can be made in a beastmode (see attached picture). If you make this in a 'dynamic textbox' card, you can set this as a header on your dashboard.
I don't know how to update the time every second.
Best regards,
Koen
0 -
Hi,
thanks for your answer however this date format is required in a connector API call in order to drag the data into Domo.
simon
0 -
Hi there,
If I understood you correctly, you're building a custom connector in Domo and need the current date in the format you specified in order to make an API call. You can do that using pure JavaScript with the code below:
var options = {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false
}
today = new Date();var formattedDate = today.toLocaleDateString("en-AU", options) + ' GMT';
console.log(formattedDate);
I've just concatenated the " GMT" part on the end for simplicity
Cheers
Eric
EDIT: documentation for the toLocaleDateString method
0 -
Eric,
Thats great thanks. Just a minor tweak I get date
Fri., 11 Oct. 2019, 09:28:00 GMT
but need
Fri, 11 Oct 2019 09:28:00 GMT
Just a fullstop and a comma removed
I will have a look but if you know how that would be great
Thanks
0 -
Here's a little more formatting to get the result you need:
var options = {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false
}
today = new Date();var date = today.toLocaleDateString("en-AU", options) + ' GMT';
// Replace period with nothing
var date1 = date.replace(".", "");// Replace all instances of a comma with nothing
var date2 = date1.replace(/,/g, "");// Re-add the comma after the weekday
var final = date2.substring(0, 3) + ', ' + date2.substring(4);
console.log(final);
Cheers
Eric
1 -
Great thanks
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 57 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive