如何更改迄今为止的毫秒数

Joh*_*per 3 flutter

AppoinmentList页面 - 我需要为此页面添加代码以更改迄今为止的毫秒数。有人可以帮助我吗?约会UnixTime": 1646274840000,

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


class AppoinmentList extends StatefulWidget {
  int ts = 1646274840000;
  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: _appoinmentListUI(),
    );
  }
  _appoinmentListUI() {
  return FutureBuilder(
    future: APIService.getAppointmentList(widget.token!),
    
    builder: (
      
      BuildContext context,
      AsyncSnapshot<String?> model,
    ){
      if (model.hasData) {
        return Column(
          children: [
            Text("Token",
            style: TextStyle(
              fontWeight: FontWeight.bold,
            ),
            ),
            Text(widget.token!),
            Text("Response Message",
            style: TextStyle(
              fontWeight: FontWeight.bold,
            ),
            ),
            Text(model.data!),
            
          ],
        );
      }
      
      return const Center(
        child: CircularProgressIndicator(),
      );
    }
  );
  }
}
Run Code Online (Sandbox Code Playgroud)

我成功调用令牌,但我不知道我需要添加哪一部分代码来更改迄今为止的毫秒数。我知道使用颤振。有人可以告诉我吗?

这是我从邮差那里得到的询问

Chi*_*iya 5

您可以使用以下代码将毫秒转换为日期:-

int ts = 1646274840000;
var dt = DateTime.fromMillisecondsSinceEpoch(ts);

var date = DateFormat('MM/dd/yyyy, hh:mm a').format(dt);
print(date);
Run Code Online (Sandbox Code Playgroud)

输出:

03/03/2022, 08:04 AM
Run Code Online (Sandbox Code Playgroud)