简体   繁体   English

实例化一个日期 object,给定时间作为字符串和时区?

[英]Instantiate a Date object, given time as a string and a timezone?

I have a PST time in String format, I need to convert this to a String in system time.我有一个字符串格式的 PST 时间,我需要将其转换为系统时间的字符串。

moment.js isn't working for me right now since moment.tz("1970-8-31 1:15", "America/Los_Angeles");moment.tz("1970-8-31 1:15", "America/Los_Angeles");以来, moment.js现在不适合我throws a TypeError: _moment.default.tz is not a function error.引发TypeError: _moment.default.tz is not a function错误。

This should work.这应该有效。

const moment = require('moment-timezone');

var june = moment("1970-8-31 1:15");

console.log(june.tz('America/Los_Angeles').format('ha z'));

// or

console.log(moment(june).tz('America/Los_Angeles').format('ha z'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用JavaScript将带有时区的日期字符串转换为本地时间的日期对象 - Use JavaScript to convert a date string with timezone to a date object in local time 从日期字符串 + 时间字符串 + 时区偏移字符串创建 JavaScript 日期 object - Create JavaScript Date object from date string + time string + timezone offset string 给定一个时区字符串,如何在JS中将该日期对象设置为该TZ - given a timezone string, how can i set a date object to that TZ in JS 日期选择器获取给定时区的日期而不是本地时间 - Date Picker get Date in given timezone instead of local time 将时区附加到作为日期对象的时间上 - Append timezone to time which is a date Object 从字符串和时区构建日期对象 - Build Date object from string and timezone 将字符串转换为 UTC timeZONE 中的新 Date 对象 - Convert string to new Date object in UTC timeZONE 将没有时区的日期字符串转换为特定时区时刻 object - Convert date string without timezone to specific timezone moment object 给定日期/时间和时区,如何将其转换为UTC时间戳? - Given a date/time and timezone, how do you convert that into a UTC timestamp? 如何使用给定时区偏移量的时刻获取日期和时间 - How to get date and time using moment for a given timezone offset
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM