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.7K Product Ideas
- 1.7K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 292 Workbench
- 4 Cloud Amplifier
- 8 Federated
- 2.8K Transform
- 95 SQL DataFlows
- 600 Datasets
- 2.1K Magic ETL
- 3.7K Visualize
- 2.4K Charting
- 687 Beast Mode
- 43 App Studio
- 38 Variables
- 658 Automate
- 170 Apps
- 441 APIs & Domo Developer
- 42 Workflows
- 5 DomoAI
- 32 Predict
- 12 Jupyter Workspaces
- 20 R & Python Tiles
- 385 Distribute
- 110 Domo Everywhere
- 269 Scheduled Reports
- 6 Software Integrations
- 112 Manage
- 109 Governance & Security
- 8 Domo University
- 25 Product Releases
- Community Forums
- 39 Getting Started
- 29 Community Member Introductions
- 98 Community Announcements
- Domo Community Gallery
- 4.8K Archive