需要帮助格式化日期时间保存在数据库中 [英] Need help in formating datetime as saved in database

查看:100
本文介绍了需要帮助格式化日期时间保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



在我的应用程序中我现在正在做的是我在数据库表中保存用户选择日期时间格式..

例如用户选择格式为mm-yyyy-dd



所以现在在向UI显示日期时间时我必须将日期时间格式转换为用户定义的格式。 />
我有一个datetimepicker用于选择日期



请告诉我该怎么做..

Hi all

In my application what i am doing now is i am saving the user choice datetime format in database table..
e.g. user selected the format as mm-yyyy-dd

so now while displaying the datetime to the UI i have to convert the datetime format to the user defined format.
I have a datetimepicker for selecting the date

Please tell me how to do this..

推荐答案

我想我最近在其他地方回答了这个问题。



按用户首选项格式化的数据永远不应该作为存储数据结束。用户偏好应该有效的唯一地方是通过UI向用户显示数据,同样在将用户指定的时间/日期转换为内部结构时也是如此。日期数据应该在内存中使用,并以程序员选择的一致形式保存到存储中。



我对所有存储时间/日期字段的个人建议是 ISO 8601 [ ^ ]。
I think I answered this elsewhere recently.

Data formatted per user preferences should never end up as stored data. The only place that user preference should be effective is when displaying the data to the user through the UI, and likewise going the other way when translating a user specified time/date to internal structure. The date data should be used in memory and persisted to storage in a consistent form that you, the programmer, choose.

My personal recommendation for all stored time/date fields is ISO 8601[^].


好的,有关日期格式的讨论有两个问题:

1 )MS SQL Server端的格式化日期,

2)使用VB.NET,C#或任何其他.NET编程语言在客户端格式化日期





ad 1)

要在服务器端格式化日期,请参阅设置DATEFORMAT语句 [ ^ ]。注意:有一些限制。

我建议你使用 ymd 格式 - 参见H.Brydon解决方案/推荐;)





ad 2)

VB.NET或C#中的格式化日期很简单。请参阅:自定义日期和时间格式字符串 [ ^ ]。



摘要:

如果你可以从数据库中获取日期和字符串日期格式,你可以做你想做的一切;)



要更改DateTimePicker的字符串日期格式,请参阅:显示使用Windows窗体DateTimePicker控件的自定义格式的日期 [ ^ ]



启动是否足够?
OK, there are 2 issues to discuss with concerning with date formatting:
1) formatting date on MS SQL Server side,
2) formatting date on client side using VB.NET, C# or any other .NET programming language


ad 1)
To format date on server side, see SET DATEFORMAT statement[^]. Note: there are some restrictions.
I would recommend you to use ymd format - see H.Brydon solution/recommendation ;)


ad 2)
Formatting date in VB.NET or C# is simple. See this: Custom Date and Time Format Strings[^].

Summary:
If you can get the date and string-date-format from database, you can do everything what you want to do ;)

To change string-date-format for DateTimePicker, see this: Displaying a Date in a Custom Format with the Windows Forms DateTimePicker Control[^]

Is it enough for start?


检查这希望它有所帮助:



datetime-format [ ^ ]
check this hope it help :

datetime-format[^]


这篇关于需要帮助格式化日期时间保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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