如何在我的代码中放置两个毫秒转换日期

发布于 2025-01-11 14:25:49 字数 1494 浏览 0 评论 0原文

这种编码方式正确吗?如何显示 2 个日期。有人可以帮助我检查和纠正我的编码吗? int ts=1646274840000; int ts2=1646015654686;

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

import 'api_service.dart';

class AppoinmentList extends StatefulWidget {
  final String? token;
  AppoinmentList({
    Key? key,
    this.token
  }) : super(key: key);

  @override
  _AppoinmentListState createState() => _AppoinmentListState();
}

class _AppoinmentListState extends State<AppoinmentList> {
  @override
  void initState() {
    super.initState();
    APIService.getAppointmentList(widget.token!);
    
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Appointment Listing"),
      ),
      body: _time()
      
    ); 
      //body: _appoinmentListUI(),
  }
}
      _time() {
        
        int ts=1646274840000;
        int ts2=1646015654686;
        

        DateTime tsdate = DateTime.fromMillisecondsSinceEpoch(ts);
        DateTime ts2date = DateTime.fromMillisecondsSinceEpoch(ts2);
        String fdatetime = DateFormat('MM/dd/yyyy, hh:mm a').format(tsdate);
        String fdatetime2 = DateFormat('MM/dd/yyyy, hh:mm a').format(ts2date);
    return Container(
child: Text(fdatetime,),

);

}

我只成功地显示了一个日期的输出。如何显示两个日期?有人可以帮助我。

此输出仅显示一个日期

此输出仅显示一个日期

Is this way of coding correct, and how do show 2 dates. Can someone help me to check and correct my coding? int ts=1646274840000; int ts2=1646015654686;

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

import 'api_service.dart';

class AppoinmentList extends StatefulWidget {
  final String? token;
  AppoinmentList({
    Key? key,
    this.token
  }) : super(key: key);

  @override
  _AppoinmentListState createState() => _AppoinmentListState();
}

class _AppoinmentListState extends State<AppoinmentList> {
  @override
  void initState() {
    super.initState();
    APIService.getAppointmentList(widget.token!);
    
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Appointment Listing"),
      ),
      body: _time()
      
    ); 
      //body: _appoinmentListUI(),
  }
}
      _time() {
        
        int ts=1646274840000;
        int ts2=1646015654686;
        

        DateTime tsdate = DateTime.fromMillisecondsSinceEpoch(ts);
        DateTime ts2date = DateTime.fromMillisecondsSinceEpoch(ts2);
        String fdatetime = DateFormat('MM/dd/yyyy, hh:mm a').format(tsdate);
        String fdatetime2 = DateFormat('MM/dd/yyyy, hh:mm a').format(ts2date);
    return Container(
child: Text(fdatetime,),

);

}

I only success to show the output for one date only. How to show two dates? Someone can help me.

This output show for one date only

This output show for one date only

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风渺 2025-01-18 14:25:49

_time() 仅返回第一个日期的一个 Text 小部件。您需要为第二次约会添加另一个。

将两个 Text 小部件放入 Column< /code>如果您希望它们彼此重叠。
像这样:

_time() {
  int ts = 1646274840000;
  int ts2 = 1646015654686;

  DateTime tsdate = DateTime.fromMillisecondsSinceEpoch(ts);
  DateTime ts2date = DateTime.fromMillisecondsSinceEpoch(ts2);
  String fdatetime = DateFormat('MM/dd/yyyy, hh:mm a').format(tsdate);
  String fdatetime2 = DateFormat('MM/dd/yyyy, hh:mm a').format(ts2date);

  return Column(
    // To make children align to the left of the screen
    crossAxisAlignment: CrossAxisAlignment.start,

    // to prevent `Column` from expanding.
    mainAxisSize: MainAxisSize.min,

    children: [
      Text(fdatetime),
      Text(fdatetime2),
    ],
  );
}

_time() only returns one Text widget for the first date. You need to add another one for the second date.

Put both Text widgets in a Column if you want them on top of each other.
like this:

_time() {
  int ts = 1646274840000;
  int ts2 = 1646015654686;

  DateTime tsdate = DateTime.fromMillisecondsSinceEpoch(ts);
  DateTime ts2date = DateTime.fromMillisecondsSinceEpoch(ts2);
  String fdatetime = DateFormat('MM/dd/yyyy, hh:mm a').format(tsdate);
  String fdatetime2 = DateFormat('MM/dd/yyyy, hh:mm a').format(ts2date);

  return Column(
    // To make children align to the left of the screen
    crossAxisAlignment: CrossAxisAlignment.start,

    // to prevent `Column` from expanding.
    mainAxisSize: MainAxisSize.min,

    children: [
      Text(fdatetime),
      Text(fdatetime2),
    ],
  );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文