AppoinmentList
page - which part I need to add code for this page for change milisec to date. Someone can help me?
appointmentUnixTime": 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(),
);
}
);
}
}
I success to call token but I don't know which part I need to add code for change milisec to date. I knew using flutter. Can someone tell me?
CodePudding user response:
You can use Following code to convert millisec to date:-
int ts = 1646274840000;
var dt = DateTime.fromMillisecondsSinceEpoch(ts);
var date = DateFormat('MM/dd/yyyy, hh:mm a').format(dt);
print(date);
Output:
03/03/2022, 08:04 AM
CodePudding user response:
Use this simple line to convert
var date = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);