Created
January 14, 2022 20:49
-
-
Save ambiorixg12/5f2692be5810c412976b80840810bfdd to your computer and use it in GitHub Desktop.
Twilio phone number time zone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.handler = function(context, event, callback) { | |
let to = event.To; | |
const nums = [to,+1,+2,+3]; | |
let n1 =nums[0]; | |
let n2= nums[1]; | |
let n3= nums[2]; | |
let n4 =nums[3]; | |
const number_tzone = {n1:"America/New_York",n2:"America/Miami"}; | |
console.log(number_tzone.n1); | |
console.log(n1) | |
// Date object initialized as per New Zealand timezone. Returns a datetime string | |
let nz_date_string = new Date().toLocaleString("en-US", { timeZone:number_tzone.num }); | |
// Date object initialized from the above datetime string | |
let date_nz = new Date(nz_date_string); | |
// year as (YYYY) format | |
let year = date_nz.getFullYear(); | |
// month as (MM) format | |
let month = ("0" + (date_nz.getMonth() + 1)).slice(-2); | |
// date as (DD) format | |
let date = ("0" + date_nz.getDate()).slice(-2); | |
// hours as (HH) format | |
let hours = ("0" + date_nz.getHours()).slice(-2); | |
// minutes as (mm) format | |
let minutes = ("0" + date_nz.getMinutes()).slice(-2); | |
// seconds as (ss) format | |
let seconds = ("0" + date_nz.getSeconds()).slice(-2); | |
// date as YYYY-MM-DD format | |
let date_yyyy_mm_dd = year + "-" + month + "-" + date; | |
console.log("Date in YYYY-MM-DD format: " + date_yyyy_mm_dd); | |
// time as hh:mm:ss format | |
let time_hh_mm_ss = hours + ":" + minutes + ":" + seconds; | |
console.log("Time in hh:mm:ss format: " + time_hh_mm_ss); | |
// date and time as YYYY-MM-DD hh:mm:ss format | |
let date_time = year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds; | |
console.log("Date and Time in YYYY-MM-DD hh:mm:ss format: " + date_time + to) | |
let twiml = new Twilio.twiml.VoiceResponse(); | |
//// here you pass the SMS parameters and function value to Twilio studio | |
callback(null, twiml); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment