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.1K Product Ideas
- 1.1K Ideas Exchange
- 1.2K Connect
- 969 Connectors
- 257 Workbench
- Cloud Amplifier
- 1 Federated
- 2.4K Transform
- 76 SQL DataFlows
- 501 Datasets
- 1.8K Magic ETL
- 2.7K Visualize
- 2.2K Charting
- 375 Beast Mode
- 20 Variables
- 485 Automate
- 103 Apps
- 378 APIs & Domo Developer
- 6 Workflows
- 22 Predict
- 6 Jupyter Workspaces
- 16 R & Python Tiles
- 316 Distribute
- 64 Domo Everywhere
- 252 Scheduled Reports
- 59 Manage
- 59 Governance & Security
- 1 Product Release Questions
- 5K Community Forums
- 37 Getting Started
- 23 Community Member Introductions
- 63 Community Announcements
- 4.8K Archive