![]() ![]() Sets Kind of the given DateTime (using the DateTime.SpecifyKind(.) method) to the Kind of the current Clock if given DateTime's Kind is Unspecified.Converts the given DateTime to the local (by using the DateTime.ToLocalTime() method) if current Clock is local and given DateTime is UTC.Converts the given DateTime to the UTC (by using the DateTime.ToUniversalTime() method) if current Clock is UTC and given DateTime is local.Normalize method works as described below: ![]() Var normalizedDateTime = Clock.Normalize(dateTime) Other important function of the IClock is to normalize DateTime objects.Įxample usage: DateTime dateTime =. Either make it Utc or Local if you want to get benefit of the Clock system. Write this inside the ConfigureServices method of your module.ĭefault Kind is Unspecified, that actually make the Clock as it doesn't exists at all. Clock OptionsĪbpClockOptions is the options class that used to set the clock kind.Įxample: Use UTC Clock Configure(options => Most of the times, IClock is the only service you need to know and use in your application. Use the Now property to get the current time.Common base classes (like ApplicationService) already injects it and provides as a base property - so, you can directly use as Clock. Inject the IClock service when you need to get the current time.Public class MyService : ITransientDependency IClock provides an abstraction while getting the current time, so you can control the kind of the date time (UTC or local) in a single point in your application.Įxample: Getting the current time using In this way, you can convert it to the time zone of the target client when needed. One solution to this problem is always use DateTime.UtcNow and assume all DateTime objects as UTC time. The things especially gets complicated when you save this value to a database and read later, or send it to a client in a different time zone. You can only make assumptions, like assuming that it was created in UTC+05 time zone. So, you can not know the absolute date & time stored in this object. A DateTime object doesn't store the time zone information. IClockĭateTime.Now returns a DateTime object with the local date & time of the server. But even in this case, it is suggested to use the IClock service introduced in this document. If you are creating a local application that runs in a single time zone region, you may not need all these systems. This document covers the ABP Framework services and systems related to time and time zones. Working with times & time zones is always tricky, especially if you need to build a global system that is used by users in different time zones.ĪBP provides a basic infrastructure to make it easy and handle automatically wherever possible. 3: Creating, Updating and Deleting Books. ![]()
0 Comments
Leave a Reply. |