I am converting a ticks value to a date like this:
我将一个节拍值转换为这样的日期:
Convert(datetime, (MachineGroups.TimeAdded - 599266080000000000)/864000000000);
Using this i get:
我使用这个:
9/27/2009 10:50:27 PM
But I want just the date in this format:
但我只想要这个格式的日期:
October 1, 2009
My sample ticks value is
我的样本节拍值是
633896886277130000
What is the best way to do this?
最好的方法是什么?
3 个解决方案
#1
148
A DateTime object can be constructed with a specific value of ticks. Once you have determined the ticks value, you can do the following:
一个DateTime对象可以用一个特定的刻度值来构造。一旦您确定了节拍值,您可以执行以下操作:
DateTime myDate = new DateTime(numberOfTicks);
String test = myDate.ToString("MMMM dd, yyyy");
#2
38
It's much simpler to do this:
这样做更简单:
DateTime dt = new DateTime(633896886277130000);
Which gives
这给了
dt.ToString() = "9/27/2009 10:50:27 PM"
tostring () = "9/27/2009 10:50:27 PM"
You can format this any way you want by using dt.ToString(MyFormat). Refer to this reference for format strings. "MMMM dd, yyyy" works for what you specified in the question.
您可以通过使用dtd . tostring (MyFormat)以任何您想要的方式对其进行格式化。有关格式字符串,请参阅此引用。“MMMM dd, yyyy”适用于您在问题中指定的内容。
Not sure where you get October 1.
不知道10月1日你在哪里。
#3
5
private void button1_Click(object sender, EventArgs e)
{
long myTicks = 633896886277130000;
DateTime dtime = new DateTime(myTicks);
MessageBox.Show(dtime.ToString("MMMM d, yyyy"));
}
Gives
给了
September 27, 2009
Is that what you need?
这就是你需要的吗?
I don't see how that format is necessarily easy to work with in SQL queries, though.
不过,我不认为在SQL查询中使用这种格式一定很容易。
#1
148
A DateTime object can be constructed with a specific value of ticks. Once you have determined the ticks value, you can do the following:
一个DateTime对象可以用一个特定的刻度值来构造。一旦您确定了节拍值,您可以执行以下操作:
DateTime myDate = new DateTime(numberOfTicks);
String test = myDate.ToString("MMMM dd, yyyy");
#2
38
It's much simpler to do this:
这样做更简单:
DateTime dt = new DateTime(633896886277130000);
Which gives
这给了
dt.ToString() = "9/27/2009 10:50:27 PM"
tostring () = "9/27/2009 10:50:27 PM"
You can format this any way you want by using dt.ToString(MyFormat). Refer to this reference for format strings. "MMMM dd, yyyy" works for what you specified in the question.
您可以通过使用dtd . tostring (MyFormat)以任何您想要的方式对其进行格式化。有关格式字符串,请参阅此引用。“MMMM dd, yyyy”适用于您在问题中指定的内容。
Not sure where you get October 1.
不知道10月1日你在哪里。
#3
5
private void button1_Click(object sender, EventArgs e)
{
long myTicks = 633896886277130000;
DateTime dtime = new DateTime(myTicks);
MessageBox.Show(dtime.ToString("MMMM d, yyyy"));
}
Gives
给了
September 27, 2009
Is that what you need?
这就是你需要的吗?
I don't see how that format is necessarily easy to work with in SQL queries, though.
不过,我不认为在SQL查询中使用这种格式一定很容易。