/ / Ustaw pole DateTime, aby wyświetlić datę i godzinę w formacie dd / mm / rrrr hh: mm: ss - c #, sql-server, data, datetime, formatowanie

Ustaw pole DateTime, aby wyświetlić datę i godzinę w formacie dd / mm / rrrr gg: mm: ss - c #, serwer sql, data, data / godzina, formatowanie

Ten kod pobiera datę z tabeli do wyświetlenia w tabeli dla użytkownika

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

Uzyskuje datę w bazie danych rrrr-mm-dd gg: mm: ss. Czy mogę wykonać jakąś metodę w DateTime zmienić formatowanie daty na dd / mm / rrrr hh: mm: ss

Odpowiedzi:

4 dla odpowiedzi № 1

Możesz przekonwertować strukturę DateTime na łańcuch, używając następującego kodu:

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

2 dla odpowiedzi nr 2

Posługiwać się

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