【发布时间】:2021-04-27 12:08:19
【问题描述】:
我还是 react(Typescript) 的新手,我想打印一个从数据库中得到但没有时间的日期。
这是我的界面:
interface Games {
g_Id: number;
g_Title: string;
g_Genre: string;
g_Plattform: string;
g_ReleaseDate: Date;
g_Price: number;}
和我的输出方法:
private static renderGamesTable(games: Games[]) {
console.log(games)
return <table className='table'>
<thead>
<tr>
<th>Title</th>
<th>Genre</th>
<th>Plattform</th>
<th>Release Date</th>
<th>Price</th>
</tr>
</thead>
<tbody>
{games.map(games =>
<tr key={games.g_Id}>
<td>{games.g_Title}</td>
<td>{games.g_Genre}</td>
<td>{games.g_Plattform}</td>
<td>{games.g_ReleaseDate}</td>
<td>{games.g_Price}</td>
</tr>
)}
</tbody>
</table>;
}
以及数据库设计
CREATE TABLE [dbo].[Games] (
[G_Id] INT IDENTITY (1, 1) NOT NULL,
[G_Genre] NVARCHAR (100) NOT NULL,
[G_Plattform] NVARCHAR (100) NOT NULL,
[G_Price] DECIMAL (18, 2) NOT NULL,
[G_ReleaseDate] DATETIME2 (7) NOT NULL,
[G_Title] NVARCHAR (100) NOT NULL,
CONSTRAINT [PK_Games] PRIMARY KEY CLUSTERED ([G_Id] ASC));
我正在使用 .Net core 和 MS-Sql(我没有添加 fetch 方法和控制器,因为我认为它们并不重要,所以请随时询问是否重要)。
到目前为止我尝试过的是:
- 更改数据库中的数据类型
- 尝试转换日期(使用 getyear 或 toDateString ...等)
- 我尝试使用 moment 更改格式
- 创建只接受日期的新日期类型
到目前为止似乎没有任何效果(可能是因为我是新手,所以我遗漏了一些明显的东西,对此感到抱歉:))
【问题讨论】:
标签: sql-server typescript react-native date