我收到DateTime来自 API的响应,该响应将时区设置为 UTC。
但是当我尝试使用toLocal()它转换接收到的数据时,它不会转换。
我的当地时间是香港时间
这是我的代码。
//TIME DIFFERENCE
getNotificationDate(DateTime date) {
date = date.toUtc();
final convertedDate = date.toLocal();
final dateNow = DateTime.now();
print('TIMENOW: ' + dateNow.toString());
print('TIMENOTIFC: ' + convertedDate.toString());
final difference = dateNow.difference(convertedDate);
print('DIFFERENCE: ' + difference.toString());
return getDurationFormat(difference);
}
Run Code Online (Sandbox Code Playgroud)
编辑:
date是DateTime我从 API 收到的。这是在UTC时区。
我使用过print('TIMEZONENAME: ' + date.timeZoneName;,它会自动将时区设置为HKT。这就是为什么当我尝试使用它时它什么也不做date.toLocal()
我不希望我的视频看起来很拉长。我使用Chewieflutter 包作为我的视频播放器。
我尝试使用_controller.value.size.aspectRatio但它返回一个错误
The getter 'aspectRatio' was called on null.
这是我从画廊获取视频的代码:
Future uploadVideoFromGallery() async {
print("CALLED");
Map<PermissionGroup, PermissionStatus> permissions =
await PermissionHandler().requestPermissions(
[PermissionGroup.storage, PermissionGroup.camera]);
if (permissions[PermissionGroup.storage] == PermissionStatus.granted) {
var videoFile = await ImagePicker.pickVideo(source: ImageSource.gallery);
if (videoFile != null) {
getVideoThumbnail(videoFile.path);
setState(() {
isFileImage = false;
image = videoFile;
_controller = VideoPlayerController.file(image);
});
print(videoFile.path);
}
} else {
debugPrint('permission not granted');
}
}
Run Code Online (Sandbox Code Playgroud)
这是我放置的代码videoFile:
Chewie(
controller: ChewieController(
videoPlayerController: _controller,
aspectRatio: _controller.value.size.aspectRatio,
materialProgressColors: ChewieProgressColors(
playedColor: …Run Code Online (Sandbox Code Playgroud)