DateTime AddMinutes method not working

后端 未结 6 828
挽巷
挽巷 2021-02-07 23:50

The purpose of my method is to get the currentTime, and set it back for 20 minutes. For what I can see, my method is correct, but the output shows something else.

This

6条回答
  •  北荒
    北荒 (楼主)
    2021-02-08 00:33

    DateTime is "immutable", what that means is you can never modify an existing instance, only make new ones. Strings are the same, for example. So you need to use the result of the AddMinutes call, which gives you your existing currentTime with the minuts variable applied.

    currentTime = currentTime.AddMinutes(minuts);
    

提交回复
热议问题