我想将00:12:30之类的时间存储在数据库中 [英] i want to store time like 00:12:30 in database

查看:63
本文介绍了我想将00:12:30之类的时间存储在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的时间值为12:12:30,但我想像00:12:30那样存储

i have time value 12:12:30 but i want to store like 00:12:30

推荐答案

在SQL数据库中存储时间时,您可以将其存储在DateTime字段中,该字段并不关心您想要哪种显示格式,因为它自任意日期以来以毫秒为单位存储.

只有当您实际显示日期和/或时间时,有关12小时/24小时显示的决定才有意义.

无论您做什么,都不要试图以字符串格式存储它!在计算间隔,关系等方面,使用适当格式的顶层工作要容易得多.
When you store a time in an SQL database, you store it in a DateTime field - which doesn''t care what kind of display format you want as it is stored as a number of milliseconds since an arbitrary date.

It is only when you actually display the date and / or time that decisions about 12 hour / 24 hour display becomes relevant.

Whatever you do, do not be tempted to store it in a string format! It is much, much easier top work with teh propper format, when it comes to working out intervals, relationships, and so forth.


这篇关于我想将00:12:30之类的时间存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆