/ / Imposta il campo DateTime per mostrare la data e l'ora nel formato gg / mm / aaaa hh: mm: ss - c #, sql-server, data, datetime, formattazione

Imposta il campo DateTime per mostrare la data e l'ora nel formato gg / mm / aaaa hh: mm: ss-c #, sql-server, data, datetime, formattazione

Questo codice ottiene la data dalla tabella da mostrare in una tabella per l'utente

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"]);
}
}

Ottiene la data come è nel database aaaa-mm-gg hh: mm: ss. Posso fare qualche metodo nel DateTime per modificare la formattazione della data in gg / mm / aaaa hh: mm: ss

risposte:

4 per risposta № 1

È possibile convertire la struttura DateTime in stringa usando il seguente codice:

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

2 per risposta № 2

Uso

Convert.ToDateTime(row["Date"]).ToString("dd/MM/yyyy HH:mm:ss")