[英]Error : SyntaxError: Unexpected token i in JSON at position 0 in React Native
react native fetching rejected with Error : SyntaxError: Unexpected token i in JSON at position 0 when applying the moment-timezone module 当应用moment-timezone模块时,对本机访存做出反应,拒绝,并出现错误:SyntaxError:JSON中位置0处的意外令牌i
i have used MomentTimezone.tz(new Date().getTime(), 'America/New_York')
as the fetching request message value 我已经使用MomentTimezone.tz(new Date().getTime(), 'America/New_York')
作为获取请求消息的值
You need to load timezone data first, before you parse timezone. 在解析时区之前,您需要先加载时区数据。 See the documentation at Moment Timezone Data Loading 请参阅时刻时区数据加载中的文档
Also I think you want to send date instead of New York Time. 另外,我认为您想发送日期而不是纽约时间。 Does your request actually requires That time can be used for display however if you have to send that time with your request (to a server) you need to convert your moment
instance to date
object like this 您的请求实际上是否需要该时间可以用于显示,但是如果您必须将时间与您的请求一起发送(到服务器),则需要像这样将您的moment
实例转换为date
对象
const now = new Date(); const myMoment = momentTimezone.tz(now.getTime(), 'America/NewYork'); const dateForRequest = myMoment.toDate();
if you want new york time, you need to specify which time do you actually want. 如果您想要纽约时间,则需要指定您实际想要的时间。 Consider I want to know what will be the time( with respect to UTC or Epoch) when New York time will be 2017-12-1 03:30
. 考虑一下我想知道纽约时间是2017-12-1 03:30
的时间(相对于UTC或Epoch)。
const timeString = '2017-12-1 03:30'
const myMoment = momentTimezone.tz(timeString, 'YYYY-MM-DD HH:mm', 'America/NewYork');
const dateForRequest = myMoment.toDate();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.