在asp.net中格式化日期 [英] Format date in asp.net

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

问题描述

此代码从SQL数据库检索日期



 LblExpirydate.Text = dataReader( 0 )。ToString()





输出:01/05/2013 12:00:00 AM



i希望将格式更改为(01/05/2013)

解决方案

 LblExpirydate.Text = dataReader( 0 )。ToString(  d


LblExpirydate.Text = dataReader(0).ToString(dd-MM-yyyy)

它在同一行返回此错误(LblExpirydate.Text = dataReader(0).ToString(d))



错误:从Stingd到整数的转换无效





 connectionString = ConfigurationManager .ConnectionStrings(  conString)。 String 
connection = New SqlConnection(connectionString)
connection.Open()
command = New SqlCommand( SELECT Max(Expirydate)FROM Act WHERE Skey ='& Request.QueryString( ID)& ',connection)
dataReader = command.ExecuteReader
dataReader.Read ()
LblExpirydate.Text = dataReader( 0 )。ToString( d
connection.Close()





< br $>
sql数据库



ActID int未选中

Skey nvarchar(100)已检查

Expirydate date Checked


this Code Retrieve Date From SQL Database

LblExpirydate.Text = dataReader(0).ToString()



output : 01/05/2013 12:00:00 AM

i want to change format to (01/05/2013)

解决方案

LblExpirydate.Text = dataReader(0).ToString("d")


LblExpirydate.Text = dataReader(0).ToString("dd-MM-yyyy")


it return me this error in the same line (LblExpirydate.Text = dataReader(0).ToString("d"))

Error : Conversion From Sting "d" to 'integer' is not valid


connectionString = ConfigurationManager.ConnectionStrings("conString").ToString
        connection = New SqlConnection(connectionString)
        connection.Open()
        command = New SqlCommand("SELECT Max(Expirydate) FROM Act WHERE Skey = '" & Request.QueryString("ID") & "'", connection)
        dataReader = command.ExecuteReader
        dataReader.Read()
        LblExpirydate.Text = dataReader(0).ToString("d")
        connection.Close()




sql database

ActID int Unchecked
Skey nvarchar(100) Checked
Expirydate date Checked


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

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