The getCurrentDateTime() function gets the current date and time in London and prints it to the console. The function also subtracts 7 hours from the current time and prints the result.
The DateTime.now() method returns the current date and time in the local time zone. In this case, the local time zone is London.
The add() method adds a duration to a DateTime object. The Duration() constructor takes an argument that specifies the number of hours to add. In this case, the number of hours to add is -7.
The print() function prints the value of the timeNow and timeDifference variables to the console.
void main() {
getCurrentDateTime(-7);
}
void getCurrentDateTime(int hourDifference) {
var timeNow = DateTime.now();
var timeDifference = timeNow.add(Duration(hours: hourDifference));
print('The time now is: $timeNow');
print('The time minus 7 hours is: $timeDifference');
}
The time now is: 2023-08-31 09:43:05.729546
The time minus 7 hours is: 2023-08-31 02:43:05.729546