excel中的时间格式导入到asp.net [英] Time format in excel imported to asp.net

查看:60
本文介绍了excel中的时间格式导入到asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个excel文件导入到asp.net中,我将其填入网格视图...



i有一个时间列在excel sheet我正在插入以下格式hh:mm,但我一直在asp.net中获取完整格式



例如:excel i中的11:11进入asp.net 12/30/1899 11:11:00 AM虽然excel中的单元格格式为h:mm



我正试图改变数据表中的值,但它不起作用......我怎么能解决这个问题?

 timee = row(  TIME_TO_SEND
finalTime = timee.Substring( 0 5
行( TIME_TO_SEND) = hh:mm





请注意,日期的转换是有效的...但我的问题是我在数据表中,日期的格式是完整的...所以当我用数据表填充网格视图时我会进入时间列:12/30/1899 11:11:00 AM

解决方案

请尝试以下代码。变量timee应该是字符串 -



 timee = Convert.ToDatetime(row(   TIME_TO_SEND))。ToString(  hh:mm); 


尝试以下示例 -



< asp:BoundField DataField =DateDataFormatString ={0:hh:mm}HeaderStyle-Horizo​​ntalAlign =LeftHeaderText =DateItemStyle-Horizo​​ntalAlign =Left/> 


i'm importing an excel file to asp.net and i'm filling it into a grid view...

i have a column for time in the excel sheet i'm inserting the following format "hh:mm" but i keep getting the full format in the asp.net

example: 11:11 in excel i get in asp.net 12/30/1899 11:11:00 AM although the format of the cell in excel is h:mm

i'm trying to change the value in the datatable but it's not working... how can i solve this?

timee = row("TIME_TO_SEND")
finalTime = timee.Substring(0, 5)
row("TIME_TO_SEND")="hh:mm"



note that the convert of the date is working... but my problem is that in the datatable the format of the date is complete... so when i'm filling the grid view with the datatable i'm getting in the time column:12/30/1899 11:11:00 AM

解决方案

Try the below code. Variable "timee" should be string -

timee =Convert.ToDatetime(row("TIME_TO_SEND")).ToString("hh:mm");


try the given below example -

<asp:BoundField DataField="Date" DataFormatString="{0:hh:mm}" HeaderStyle-HorizontalAlign="Left" HeaderText="Date" ItemStyle-HorizontalAlign="Left" />


这篇关于excel中的时间格式导入到asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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