当前位置: 首页 > 知识库问答 >
问题:

如何在flutter firebase中以日期格式显示时间戳字符串[重复]

夹谷英杰
2023-03-14
    null

    null
  Widget getHomePageBody(BuildContext context) {
    return StreamBuilder<QuerySnapshot>(
      stream: FirebaseFirestore.instance.collection('events').snapshots(),
      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (snapshot.hasError) return new Text('Error: ${snapshot.error}');
        switch (snapshot.connectionState) {
          case ConnectionState.waiting:
            return Center(
              child: CircularProgressIndicator(),
            );
          default:
            return new ListView(
              padding: EdgeInsets.only(bottom: 80),
              children: snapshot.data.docs.map((DocumentSnapshot document) {
                return Padding(
                  padding: EdgeInsets.symmetric(vertical: 3, horizontal: 10),
                  child: Card(
                    child: ListTile(
                      leading: new Image.network(
                        document['eventImageUrl'],
                        fit: BoxFit.cover,
                        width: 120.0,
                      ),
                      title: new Text(
                        'Date:' + (document['eventDate'].toDate()).DateFormat('kk:mm:a').format(),
                        style: new TextStyle(
                            color: Color(0xFF49DEE8),
                            fontSize: 14.0,
                            fontWeight: FontWeight.normal),
                      ),
                    ),
                  ),
                );
              }).toList(),
            );
        }
      },
    );
  }

共有1个答案

诸葛煜
2023-03-14
                            Expanded(
                              child: Center(
                                child: Padding(
                                  padding: const EdgeInsets.all(8.0),
                                  child: Text(
                                    model.hwPublishedDate
                                            .toDate()
                                            .hour
                                            .toString() +
                                        ":" +
                                        model.hwPublishedDate
                                            .toDate()
                                            .minute
                                            .toString() +
                                        " " +
                                        model.hwPublishedDate
                                            .toDate()
                                            .timeZoneName
                                            .toString() +
                                        ", " +
                                        model.hwDate,
                                    style: GoogleFonts.abel(
                                        color: Colors.green[500],
                                        fontSize: 15.0,
                                        fontWeight: FontWeight.bold),
                                  ),
                                ),
                              ),
                            )
                          ],
                        ),
                      ),
               ListTile(
                      leading: Icon(
                        Icons.calendar_today_sharp,
                        color: Colors.green[900],
                      ),
                      title: DateTimeField(
                        validator: (value) =>
                            value == null ? 'Provide Upload Date' : null,
                        showCursor: true,
                        cursorColor: Colors.green,
                        textCapitalization: TextCapitalization.words,
                        style: TextStyle(color: Colors.green[900]),
                        controller: _hwdateTextEditingController,
                        decoration: InputDecoration(
                            hintText: "Date",
                            hintStyle: TextStyle(
                              color: Colors.green[900],
                            ),
                            border: InputBorder.none),
                        format: DateFormat("dd-MM-yyyy"),
                        onShowPicker: (context, currentValue) {
                          return showDatePicker(
                              context: context,
                              firstDate: DateTime(1947),
                              initialDate: currentValue ?? DateTime.now(),
                              lastDate: DateTime(2100));
                        },
                        onChanged: (selectedCateg) {
                          setState(() {
                            queryString = selectedCateg.toString();
                            classSec = selectedClass + selectedSec;
                          });
                          startSearching(classSec);
                        },
                      ),
                    ),
 类似资料: