【问题标题】:How to update time for each item如何更新每个项目的时间
【发布时间】:2021-09-04 11:32:36
【问题描述】:

有人可以帮助我如何更新我在不同时间段输入的每个项目的日志时间吗?谢谢,^^。我正在使用 Moment.js

<View style={[StyleSheet.absoluteFill, {}]}>
  <Animated.View
  style={{
    justifyContent: 'space-between',
    flexDirection: 'row',
    alignItems: 'center',
    height: 50,
    padding: theme.spacing.l,
  }}
  >
  {/* revenues and expenditures will appear */}
  <Animated.Text>{item.title}</Animated.Text> 
  <Text color="silver1">
    {/* time */}
    {moment().format(' Do , h:mm:ss a')}
  </Text>
  <Animated.Text
    style={{
      opacity: hidePrice,
      color: item.price > 0 ? '#009BFC' : '#FF4500',
    }}
  >
    {item.price > 0
      ? `$${item.price}`
      : `- $${Math.abs(item.price)}`}
   </Animated.Text>
 </Animated.View>
</View>

【问题讨论】:

  • 当用户添加项目时,你想取当前日期吗?
  • 是的,这就是我想要的

标签: javascript react-native momentjs


【解决方案1】:

试试这个:

moment().format('hh:mm:ss a')

它会给你当前时间保存到一个变量并显示

结果将如下所示:06:19:18 pm

【讨论】:

    猜你喜欢
    • 2020-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 1970-01-01
    • 2012-03-21
    相关资源
    最近更新 更多