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 -
Great thanks
0
Categories
- 11K All Categories
- 5 Private Company Board
- 2 APAC User Group
- 12 Welcome
- 43 Domo News
- 10K Using Domo
- 2K Dataflows
- 2.5K Card Building
- 2.2K Ideas Exchange
- 1.2K Connectors
- 349 Workbench
- 267 Domo Best Practices
- 12 Domo Certification
- 474 Domo Developer
- 51 Domo Everywhere
- 111 Apps
- 728 New to Domo
- 85 Dojo
- Domopalooza
- 1.1K 日本支部
- 4 道場-日本支部へようこそ
- 31 お知らせ
- 65 Kowaza
- 303 仲間に相談
- 664 ひらめき共有