ABP框架系列之五十一:(Timing-定时)
Introduction
While some applications target a single timezone, some others target to many different timezones. To satisfy such needs and centralize datetime operations, Abp provides common infrastructure for datetime operations.
一些应用目标一个时区,另一些目标的许多不同的时区。为了满足这种需要,集中时间操作,abp提供了日期时间操作的公共基础。
Clock
Clock is the main class used to work with DateTime values. It defines the following static properties/methods:
- Now: Gets current time according to current provider.(根据当前提供程序获取当前时间)
- Kind: Gets DateTimeKind of current provider.(根据当前提供程序获取当前时间类型)
- SupportsMultipleTimezone: Gets a value indicates that current provider can be used for applications need to multiple timezones.(获取一个值,表明当前提供程序可以使用的应用程序需要多个时区)
- Normalize: Normalizes/converts given DateTime upon current provider(转换给定的时间为当前提供程序的时间).
So, instead of using DateTime.Now, we are using Clock.Now, which abstracts it:
DateTime now = Clock.Now;
Clock uses clock providers inside it. There are three types of built-in clock providers:(有三种类型的内置时钟提供程序)
- ClockProviders.Unspecified (UnspecifiedClockProvider):(未指定) This is the default clock provider and behaives just like DateTime.Now. It acts as you don't use Clock class at all.
- ClockProviders.Utc (UtcClockProvider): Works in UTC datetime. DateTime.UtcNow for Clock.Now. Normalize method converts a given datetime to utc datetime and set it's kind to DateTimeKind.UTC. It supports multiple timezones.
- ClockProviders.Local (LocalClockProvider): Works in Local computer's time. Normalize method converts a given datetime to local datetime and set it's kind to DateTimeKind.Local.
You can set Clock.Provider in order to use a different clock provider:
Clock.Provider = ClockProviders.Utc;
This is generally done at the beginning of an application (proper to do it Application_Start in a web application).
Client Side
Clock can be used on the client side by abp.clock object in javascript. When you set Clock.Provider on the server side, ABP automatically sets value of abp.clock.provider on the client side.
Time Zones
ABP defines a setting named Abp.Timing.TimeZone (TimingSettingNames.TimeZone constant) for storing selected timezone of host, tenant and user. ABP assumes that value of timezone setting is a valid Windows timezone name. It also defines a timezone mapping file to convert a Windows Timezone to IANA timezone since some of the common libraries are using IANA timezone id. UtcClockProvider must be used in order to support multiple timezones. Because if UtcClockProvider is used, all datetime values will be stored in UTC and all datetimes will be sent to clients in UTC format. Then on the client side we can convert UTC datetime to user's timezone by using user's current timezone setting.
ABP定义设置命名为Abp.Timing.TimeZone(timingsettingnames.timezone常数)储存宿主选择时区,租户和用户。ABP假定时区设置值是否是有效的Windows时区名称。它还定义了一个时区映射文件转换为Windows时区时区以来对IANA的一些常见的图书馆使用IANA时区ID。utcclockprovider必须为了支持多时区。因为如果utcclockprovider使用,所有日期时间值将被存储在UTC和所有日期将被送往UTC格式的客户。然后在客户端我们可以将UTCDateTime用户的时区使用用户的当前时区设置。
Client Side
ABP creates an javascript object named abp.timing.timeZoneInfo which contains timezone information for current user. This information contains Windows and IANA timezone ids and some extra information for windows timezone info. This information can be used to make client side datetime convertions and showing a datetime to user in his/her timezone.
Binders and Converters(粘合剂和转换器)
- ABP automatically normalizes DateTimes received from clients in MVC, Web API and ASP.NET Core applications, based on the current clock provider.
- ABP automatically normalized DateTimes received from database based on the current clock provider, when EntityFramework or NHibernate modules used.
If UTC clock provider is used, then all DateTimes stored in database assumed as UTC values, and all DateTimes received from clients assumed as UTC unless it's explicitly specified.
ABP框架系列之五十一:(Timing-定时)的更多相关文章
- ABP框架系列之十一:(AspNet-Core-ASPNET核心)
Introduction This document describes ASP.NET Core integration for ASP.NET Boilerplate framework. ASP ...
- ABP框架系列之五十四:(XSRF-CSRF-Protection-跨站请求伪造保护)
Introduction "Cross-Site Request Forgery (CSRF) is a type of attack that occurs when a maliciou ...
- ABP框架系列之五:(Unit Of Work-工作单元)
Introduction Connection and transaction management is one of the most important concepts in an appli ...
- ABP框架系列之五十二:(Validating-Data-Transfer-Objects-验证数据传输对象)
Introduction to validation Inputs of an application should be validated first. This input can be sen ...
- ABP框架系列之五十三:(Web-API-Controllers-Web-API-控制器)
Introduction ASP.NET Boilerplate is integrated to ASP.NET Web API Controllers via Abp.Web.Api nuget ...
- ABP框架系列之三十一:(Localization-本地化)
Introduction Any application has at least one language for user interface. Many applications have mo ...
- ABP框架系列之四十一:(Nuget-Packages-Nuget包)
Packages ASP.NET Boilerplate is distributed on nuget. Here, a list of all official packages. Abp Cor ...
- ABP框架系列之五十:(Swagger-UI-集成)
Introduction From it's web site: "....with a Swagger-enabled API, you get interactive documenta ...
- 老周的ABP框架系列教程 -》 一、框架理论初步学习
老周的ABP框架系列教程 -- 一.框架理论初步学习 1. ABP框架的来源与作用简介 1.1 简介 1.1.1 ABP框架全称为"ASP.NET Boilerplate ...
随机推荐
- [UE4]RichTextBlock
RichTextBlock:富文本 一.新建一个名为“TestRichTextBlock_0”的UserWidget,并添加名为RichTextBlock_0的RichTextBlock控件,并设置T ...
- Android 开发 框架系列 glide-transformations 图片处理基本使用
首先简单的介绍一下Gilde作用范围.Gilde功能十分强大,它可以实现图片处理.图片本地加载.图片网络加载.位图加载.图片内存缓存.图片磁盘缓存.Gif图片加载.使用简单轻松,轻松的后是它强大的心, ...
- shareSdk分享图片
/** * 只分享图片 * * @param bitmap bitmap */ private void sharedImage(Bitmap bitmap) { RxPermissions rxPe ...
- SpringBoot 之 MVC
SpringBoot MVC 和静态资源 首先,我们一定要搞清楚,mvc 配置和 static 配置的联系和区别. mvc 配置其实就是给 spring mvc 框架用的, 具体来说, 比如 @Req ...
- Linux中近期使用高频命令小结
配置定时任务命令crontab : 用来增加系统的定时任务,可以指定用户,时间,以及相关指令: 查看端口是否相通,扫描端口nc: nc -v ip地址 端口号: 转换格式命令dos2unix: 用来将 ...
- css:pointer-events: none
css3新属性pointer-events: none: pointer-events: none 顾名思义,就是鼠标事件拜拜的意思.元素应用了该 CSS 属性,链接啊,点击啊什么的都变成了 “浮云牌 ...
- 剑指offer例题——链表中倒数第K个结点
题目描述 输入一个链表,输出该链表中倒数第k个结点. 编程过程 此处采用两个指针依次后移的方法来求解,首先,用一个指针移到第k个位置,之后将第二个指针放在第一位,与第二个指针一同移动,当第二个指针移动 ...
- ArcGIS自定义工具箱-字段分割
ArcGIS自定义工具箱-字段分割 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 目的:用指定分割符分割字段, 用例:湖南省长沙市=>湖南/长沙 数据源: 使 ...
- container injection——容器技术
(一)容器技术为什么出现 在很久很久以前,想要在线上服务器部署一个应用,首先需要购买一个物理服务器,在服务器安装一个操作系统,然后安装好应用所需要的各种依赖环境,最后才可以进行应用的部署,而且一台服务 ...
- 项目(二)DNS解析——配置域名服务器
NDS服务器常见种类有:缓存域名服务器.主域名服务器.从域名服务器.DNS服务器查询方法有两种:递归查询和迭代查询.其中,递归查询是DNS服务器在本地通过缓存.本地映射.记录本得到结果,而迭代查询是D ...