gpt4 book ai didi

javascript - 单独的日期字符串和时间字符串组合成解析日期时间戳

转载 作者:搜寻专家 更新时间:2023-10-30 21:57:19 25 4
gpt4 key购买 nike

我一直在研究我是否在单独的字符串中有日期

日期 = 18-9-2018

时间为

time= 01:50 PM

and if I want to create a time stamp of the above two variables how i am supposed to have that?

手头的问题是我从 API 接收这些变量 端点,我需要有准确的时间戳,以便我可以将它们用作本地提醒通知 确切的时间和日期!

这是我到目前为止尝试过的

  createTheLocalAlert(appointments) {
// Schedule delayed notification
appointments.description.forEach(appointment => {
let notificationText =
`you have meeting with ${appointment.name} today at ${appointment.meeting_start}`;

let theDate = appointment.appointment_date.split("-");
let newDate = theDate[1] + "/" + theDate[0] + "/" + theDate[2];
let DateWithTime = newDate + appointment.meeting_start;
// alert(new Date(newDate).getTime()); //will alert 1330210800000
// console.warn("theTime_is===>" + new Date(DateWithTime));

this.localNotifications.schedule({
text: notificationText,
trigger: {at: new Date(new Date(DateWithTime).getTime() - 7200)}, // 2 hours before meetup
led: 'FF0000',
vibrate: true,
icon: 'assets/imgs/logo.jpg',
sound: null
});
});
}

I am able to convert the date into stamp but I am un able to figure out a way of adding the time into the date and parse out exact time Stamp on that date and time .

**

我们将不胜感激任何形式的帮助。

最佳答案

试试下面的代码。

    formatDateWithTime(date,time){
if(date && time){
let splitDate = date.split('-');
let splitTime = time.split(':');
let formattedDate:any;
return formattedDate = new Date(splitDate[ 2 ], splitDate[ 1 ] - 1, splitDate[ 0 ],splitTime[ 0 ], splitTime[ 1 ],
}else{
return 0
}
}

关于javascript - 单独的日期字符串和时间字符串组合成解析日期时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53020808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com