Convert Epoch Time to Standard Time and Assign to Attribute
1630526066
Ever wondered what this could possibly mean when it shows up in your database or CRM? Us, too. Unless you're one of our native integrations or a wizard or a human spreadsheet who can instantly calculate the number of seconds elapsed since January 1, 1970, then the following solution may come in handy.
function convertTimestamp(timestamp) {
var d = new Date(timestamp),
MM = ('0' + (d.getMonth() + 1)).slice(-2),
dd = ('0' + d.getDate()).slice(-2),
yyyy = d.getFullYear(),
hh = d.getHours(),
mm = ('0' + d.getMinutes()).slice(-2),
ss = ('0' + d.getSeconds()).slice(-2),
time;
time = MM + '/' + dd + '/' + yyyy + ' ' + hh + ':' + mm + ':' + ss;
return time;
};
window.drift.on("scheduling:meetingBooked", function(data) {
var meeting_time = convertTimestamp(data.meeting.time);
drift.api.setUserAttributes({
team_member: data.teamMember.name,
new_meeting_time: meeting_time
});
});
In this example, we converted epoch time to standard time using a bit of wizardry (ahem, math) and took it a step further by setting it as a user attribute new_meeting_time
any time someone books a meeting.
If you need explicit time conversions, add this code to your Drift snippet, and bask in the knowledge that your timestamp is not only exported as computer-readable, but human-readable, too.
Updated over 3 years ago