我有一个日期/时间值的字段,如下所示:
2009-11-17 18:40:05
Run Code Online (Sandbox Code Playgroud)
它是UTC.在查询中如何将其转换为EST?
我正在尝试这样的东西,但它会引发错误.
// datetime is the field name
SELECT
FROM_TZ(TIMESTAMP TO_DATE(datetime, 'yyyy-mm-dd hh24miss'), 'EST') AS DT
FROM
db_name
Run Code Online (Sandbox Code Playgroud) 我正在尝试从DateTime对象创建一个生成格式的字符串mm:dd:yyyy.
通常,该DateTime对象来自mm:dd:yyyy hrs:min:sec AM/PM.
有没有办法快速删除hrs:min:sec AM/PMDateTime 的部分,以便当我转换它时,ToString()它只会导致mm:dd:yyyy?
我正在使用以下代码
// Model
[DisplayFormat(
ApplyFormatInEditMode = true,
DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime StartDate { get; set; }
// View
@Html.EditorFor(model => model.StartDate)
Run Code Online (Sandbox Code Playgroud)
格式化,StartDate但结果是xx-xx-xxxx而不是xx/xx/xxxx.如何解决这个问题并始终使用xx/xx/xxxx格式?
更新:
改变文化en-US似乎工作:
var culture = new CultureInfo(userCulture);
System.Threading.Thread.CurrentThread.CurrentCulture = "en-US";
System.Threading.Thread.CurrentThread.CurrentUICulture = "en-US";
Run Code Online (Sandbox Code Playgroud)
但这不是一个解决方案,因为我可能正在使用不同的文化,我仍然希望以不同的方式显示日期.
如果当前文化告知应显示日期,dd-MM-yyyy则使用DisplayFormat上述方法无效并且日期不显示dd/MM/yyyy.
我正在玩Sqlite并在尝试回读一些测试数据时不断收到错误.例如,我创建了一个带有单个表和一些列的简单数据库,并使用一些测试数据填充它,如下所示.
sqlite> .schema
CREATE TABLE "shows"(id integer primary key asc autoincrement, showName TEXT, guest TEXT, dateAired date, dateWatched date);
sqlite> select * from shows;
6|test show|test guest 1|2012.05.01|2012.07.10
7|test show|test guest 2|2012.05.02|2012.07.10
8|test show|test guest 4|2012.05.04|2012.07.10
Run Code Online (Sandbox Code Playgroud)
我正在使用此处提供的System.Data.Sqlite库,但在尝试读取日期列时它一直给我一个错误.我尝试将日期设置为dd-MM-yyyy格式,但仍然会收到错误消息"字符串未被识别为有效日期时间".我已经尝试使用DateTime.Parse或将其转换为datetime或只是ToString()来查看发生了什么,但我一直得到同样的错误.我可以很好地阅读文本字段,但无法读取日期字段.
我的C#代码剪断如下
var sqliteConn = new SQLiteConnection("Data Source=data/shows.db;Version=3;New=False;Compress=True");
sqliteConn.Open();
SQLiteCommand cmd = new SQLiteCommand(sqliteConn);
cmd.CommandText = "select * from shows";
SQLiteDataReader reader = cmd.ExecuteReader( );
while (reader.Read( ))
{
var showName = reader["showName"];
// This is where it keeps giving me an …Run Code Online (Sandbox Code Playgroud) 使用java.time框架,我想以格式打印时间hh:mm:ss,但是以格式LocalTime.now()给出时间hh:mm:ss,nnn.我试着用DateTimeFormatter:
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_TIME;
LocalTime time = LocalTime.now();
String f = formatter.format(time);
System.out.println(f);
Run Code Online (Sandbox Code Playgroud)
结果:
22:53:51.894
Run Code Online (Sandbox Code Playgroud)
如何从时间中删除毫秒?
我正在进行获取以从java中的数据库获取日期(日期应该始终是2014-01-01T00:00:00).我得到以下时间了:2014-01-01T00:00:00.588Z.
我的问题是,最后的" 588Z"是什么?这个数字会不同,检索是在不同的时区完成的吗?即数字588在不同时区是不同的数字.
感谢您提供的任何帮助.
我最近升级到Windows 10 - 我现在看到使用"tt"格式说明符时日期输出中出现了一些意外的变化.
以下是一些演示此问题的代码:
using System.IO;
using System;
using System.Globalization;
using System.Threading.Tasks;
class Program
{
static void Main()
{
var cultures = new string[] {null, "en-NZ", "en-US", "en-AU", "en-GB"};
foreach (var culture in cultures) {
if (culture != null) {
var c = CultureInfo.GetCultureInfo(culture);
System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture = c;
}
DateTime dt = new DateTime(2015, 1, 2, 3, 4, 5, DateTimeKind.Utc);
Console.WriteLine("selection: {0} CurrentThread.CurrentCulture.Name: {1} CurrentThread.CurrentUICulture.Name: {2} Value: {3}",
culture ?? "ambient",
System.Threading.Thread.CurrentThread.CurrentCulture.Name,
System.Threading.Thread.CurrentThread.CurrentUICulture.Name,
dt.ToString("hhh:mm tt"));
}
}
} …Run Code Online (Sandbox Code Playgroud) 我想用格式将字符串格式化为dateTime
"yyyyMMdd HH:mm:SS.ms"
Run Code Online (Sandbox Code Playgroud)
我尝试将其"yyyyMMdd HH:mm:SS"作为字符串格式,ParseExact但它无法识别它.也不知道如何包括毫秒
任何帮助?
如何 在Date对象中解析此日期字符串2013-03-13T20:59:31 + 0000?
我尝试过这种方式,但不工作.
DateFormat df = new SimpleDateFormat("YYYY-MM-DDThh:mm:ssTZD");
Date result = df.parse(time);
Run Code Online (Sandbox Code Playgroud) 这些日期时间格式是什么?我需要将它们转换为相同的格式,以检查它们是否相同.这些只是两个来自不同的数据源,所以我需要找到一种方法来使它们具有相同的格式.有任何想法吗?
2013-07-12T07:00:00Z
2013-07-10T11:00:00.000Z
提前致谢