QDateTime 可以使用 toString() 函数转换为 QString。
QDateTime current_datetime = QDateTime::currentDateTime();
QString current_datetime_string = current_datetime.toString("yyyy-MM-dd hh:mm:ss");
其中,"yyyy-MM-dd hh:mm:ss" 是格式化字符串,可以按照需要自定义。
可选的格式化字符有:
- d 日 (1~31)
- dd 日 (01~31)
- ddd 三个字母缩写星期几
- ddd