MySQL上的NOW()和CURDATE()在C#上返回不同的格式

时间:2016-08-24 14:32:57

标签: c# mysql win-universal-app uwp

在MySQL Workbench上:

SELECT NOW()     -> '2016-08-24 21:26:12'
SELECT CURDATE() -> '2016-08-24'

这是我想要的结果,但是在我用C#编写的UWP应用程序中:

public static string CurrentDate()
{
    using (var connection = OpenConnection())
    {
        connection.Open();
        var command = connection.CreateCommand();
        command.CommandText = "SELECT CURDATE();";
        string date = command.ExecuteScalar().ToString();
        connection.Close();
        return date;
    }
}

public static string Now()
{
    using (var connection = OpenConnection())
    {
        connection.Open();
        var command = connection.CreateCommand();
        command.CommandText = "SELECT NOW();";
        string date = command.ExecuteScalar().ToString();
        connection.Close();
        return date;
    }
}

Now()         -> '24-Aug-16 9:26:12 PM'
CurrentDate() -> '24-Aug-16 12:00:00 AM'

这是否与我的计算机上的本地时间设置有关?如何确保结果与MySQL Workbench中的结果相同?

0 个答案:

没有答案