gpt4 book ai didi

c# - 设置字段 DateTime 以 dd/mm/yyyy hh :mm:ss 格式显示日期和时间

转载 作者:太空宇宙 更新时间:2023-11-03 19:05:51 24 4
gpt4 key购买 nike

此代码从表中获取日期以显示在用户的表中

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

最佳答案

您可以使用以下代码将 DateTime 结构转换为字符串:

var dt = DateTime.Now;
string str = dt.ToString("yyyy-MM-dd hh:mm:ss"); //(For month use caps 'MM')

关于c# - 设置字段 DateTime 以 dd/mm/yyyy hh :mm:ss 格式显示日期和时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27823817/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com