このコードは、ユーザのテーブルに表示するためにテーブルから日付を取得します。
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace Form
{
public class RelUso
{
public DateTime Date { get; set; }
}
public RelUso()
{
atribuiValores(row);
}
public RelUso(DataRow row)
{
assignValues(row);
}
protected void assignValues(DataRow row)
{
this.Data = Convert.ToDateTime(row["Date"]);
}
}
データベースyyyy-mm-dd hh:mm:ssの日付を取得します。でいくつかの方法を実行できますか DateTime
日付のフォーマットをdd / mm / yyyyに変更する場合hh:mm:ss
回答:
回答№1は4次のコードを使用してDateTime構造体を文字列に変換できます。
var dt = DateTime.Now;
string str = dt.ToString("yyyy-MM-dd hh:mm:ss"); //(For month use caps "MM")
回答№2については2
つかいます
Convert.ToDateTime(row["Date"]).ToString("dd/MM/yyyy HH:mm:ss")