cph*_*pot 0 node.js momentjs react-native
我正在研究一个本机应用程序,我正在尝试使用片刻格式化日期.
日期看起来像"02-16-2016 09:04:23"
function formatTime(date){
var formattedDate = moment(date).format('MM:ss A');
return formattedDate;
}
Run Code Online (Sandbox Code Playgroud)
如果chrome调试器处于活动状态,则工作正常.但如果我禁用它,我得到的只是"无效日期"
与我正在使用的解码功能相同
var that = this;
MessagesService.getMessageBody(selectedMessage)
.then(function(messageBody){
var decodedData = window.atob(messageBody.messages);
that.setState({
messageBody: decodedData
})
})
.catch(function(err){
console.log(err);
})
Run Code Online (Sandbox Code Playgroud)
用,显示解码数据
<Text> Body: {this.state.messageBody} </Text>
Run Code Online (Sandbox Code Playgroud)
并显示日期
<View style = {[MessageStyles.senderItem, MessageStyles.date]}>
<Text>
{this.formatTime(message.createDateTime)}
</Text>
</View>
Run Code Online (Sandbox Code Playgroud)
也许这是一个糟糕的方式来做反应本机?还在学习,所以我可能会做一些不好的练习.
我最近了解到,在使用chrome调试器时,react native使用不同的JS引擎.调试期间使用chrome JS引擎,否则使用JavaScriptCore.根据这篇文章
http://ruoyusun.com/2015/11/01/things-i-wish-i-were-told-about-react-native.html
但是对于日期的实际问题,JavaScriptCore引擎似乎不喜欢使用 - 解析日期.我必须使用正则表达式来替换 - 和/然后我的所有日期操作工作正常.
02-16-2016 09:04:23被视为无效
02/16/2016 09:04:23被认为是有效的
| 归档时间: |
|
| 查看次数: |
810 次 |
| 最近记录: |