Created
May 3, 2024 20:21
-
-
Save stargazing-dino/d8824637b93dc22f6a45046ed1252ba4 to your computer and use it in GitHub Desktop.
Get date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:intl/intl.dart'; | |
void main() { | |
String _generateDatetime() { | |
return DateTime.now() | |
.toUtc() | |
.toString() | |
.replaceAll(RegExp(r'\.\d*Z$'), 'Z') | |
.replaceAll(RegExp(r'[:-]|\.\d{3}'), '') | |
.split(' ') | |
.join('T'); | |
} | |
var now = _generateDatetime(); | |
now = _getDate(now); | |
print(now); | |
final other = DateFormat('yyyyMMdd').format(DateTime.now().toUtc()); | |
print(other); | |
print(now == other); | |
} | |
String _getDate(String dateTime) { | |
return dateTime.substring(0, 8); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment