如何自定义&在GridView中显示时间 [英] how to customize & show the timing in GridView

查看:84
本文介绍了如何自定义&在GridView中显示时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我的数据库将以24小时格式返回时间,如下所示.

2012-04-10T21:30:00

但是我只需要在GridView中显示时序,如下所示

检索格式所需格式
2012-04-10T21:30:00 9:30 PM
2012-04-10T09:30:00 9:30 AM

我只需要从此&中提取时间我需要以指定格式在GridView中显示.

我该如何实现?

解决方案

尝试一下:

 RetrievedValue.ToString(" );  pre> 
嘿,您可以随时为该URL添加书签以供参考-自定义日期和时间格式字符串 [ ^ ]

希望这对您有帮助!


如果您使用的是BoundField,DynamicField或类似内容,只需将DataFormatString属性设置为"hh:mm tt".

如果您使用的是TemplateField和Eval()或Bind(),则可以将格式字符串作为第二个参数传递给它们:

 Eval("   hh:mm tt")



当然,这仅在您从数据库返回DateTime时有效.
如果将其作为字符串返回,它将无法正常工作.


Dear All,

My database will return the time in the format of 24hrs as follows.

2012-04-10T21:30:00

But i need to show only timing in GridView as follows

Retrieving Format Required format
2012-04-10T21:30:00 9:30PM
2012-04-10T09:30:00 9:30AM

I need to extract only timing from this & i need to show in GridView as specified format.

How can i achieve this?

解决方案

Try this:

RetrievedValue.ToString("hh:mm tt");


And hey you can always bookmark this URL for reference - Custom Date and Time Format Strings[^]

Hope this helps!


If you''re using BoundField, DynamicField or similar, just set DataFormatString property to "hh:mm tt".

If you''re using TemplateField and Eval() or Bind() you can pass format string as second parameter to them:

Eval("Date", "hh:mm tt")



Of course, this will work only if you return DateTime from database.
It won''t work if you return it as string.


这篇关于如何自定义&在GridView中显示时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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