firebase - 如何将 localTime 转换为正常时间?
问题描述
有截图在我的应用程序中,我创建了一个聊天。当有人发送消息时,也有一段时间用户发送了他的消息。但我不希望整个时间都在显示,而只是像(14:36)这样的正常时间。有谁知道怎么做?ndnvknfkvjndkjnvfkjdnfvkjndkjvfnkjdfnv mdlkvbldfkbmkldfklbvmdflkbmvlkdf
class MessageTile extends StatelessWidget {
final String message;
final bool sendByMe;
final int time;
MessageTile({@required this.message, @required this.sendByMe, @required this.time});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: sendByMe ? CrossAxisAlignment.end : CrossAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.only(
top: 3,
bottom: 3,
left: sendByMe ? 0 : 24,
right: sendByMe ? 24 : 0),
alignment: sendByMe ? Alignment.centerRight : Alignment.centerLeft,
child: Container(
margin: sendByMe
? EdgeInsets.only(left: 30)
: EdgeInsets.only(right: 30),
padding: EdgeInsets.only(
top: 17, bottom: 17, left: 20, right: 20),
decoration: BoxDecoration(
borderRadius: sendByMe ? BorderRadius.only(
topLeft: Radius.circular(9),
topRight: Radius.circular(9),
bottomLeft: Radius.circular(9),
) :
BorderRadius.only(
topLeft: Radius.circular(9),
topRight: Radius.circular(9),
bottomRight: Radius.circular(9)),
color: sendByMe ? Colors.blue : Colors.white
),
child: Column(
children: [
Text(message,
textAlign: TextAlign.start,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontFamily: 'Orbitron',
fontSize: 12.5,),),
Text( sendByMe ? DateTime.now().toLocal().toString() : DateTime.now().toLocal().toString(),style:
TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontFamily: 'Orbitron', fontSize: 7.0,) ,
),
],
),
),
),
],
);
}
}
addMessage() {
if (messageEditingController.text.isNotEmpty) {
Map<String, dynamic> chatMessageMap = {
"sendBy": Constants.myName,
"message": messageEditingController.text,
'time': DateTime.now().millisecondsSinceEpoch,
};
DatabaseService().addMessage(widget.chatRoomId, chatMessageMap);
setState(() {
messageEditingController.text = "";
});
}
}
解决方案
Use the intl package (https://pub.dev/packages/intl) to format the DateTime to the format you want.
推荐阅读
- kendo-ui - 剑道树视图和树下拉列表 - 当前选择和同步更改
- java - 如何从我的域中检索所有邮件收件箱内容
- codeigniter - 提交后选择的下拉菜单总是改变
- android - 如何用 Fragment Scenario 测试 Fragment?
- elasticsearch - 在elasticsearch中搜索嵌套文档中除以or子句的多个字段
- sql - 如何查看 db2 服务器中最近更新的表?
- laravel - Laravel 事件触发,Echo 监听但不经过函数
- javascript - styled-component 的类型与“strict: true”不匹配
- rest - 谷歌云文本到语音 REST API 身份验证
- java - 如何在 java 中检查集合 mongo db?