[DllImport("kernel32.dll", EntryPoint = "GetSystemDefaultLCID")]
public static extern int GetSystemDefaultLCID();
[DllImport("kernel32.dll", EntryPoint = "SetLocaleInfoA")]
public static extern int SetLocaleInfo(int Locale, int dateType, string dateData);
public const int LOCALE_SLONGDATE = 0x20;
public const int LOCALE_SSHORTDATE = 0x1F;
public const int LOCALE_IDATE = 0x21;
public const int LOCALE_ILDATE = 0x22;
这是我设置系统时间的代码 上部分为网上找的(那2个设置长日期,短日期) 可以用
后2句是我查api文档找的(api32) 设置代码如下SetLocaleInfo(i, LOCALE_SSHORTDATE, "yyyy-MM-dd");
SetLocaleInfo(i, LOCALE_SLONGDATE, "yyyy-MM-dd");
SetLocaleInfo(i, LOCALE_IDATE, "HH:mm");
SetLocaleInfo(i, LOCALE_ILDATE, "HH:mm:ss");
多次测试结果表示 我的短日期格式没有设置上去 就是HH:mm系统还是12小时制度 (设置前有获取系统格式 为hh:ss 12小时制,应该为HH 24小时制)是我哪里错了吗? 求大牛..
public static extern int GetSystemDefaultLCID();
[DllImport("kernel32.dll", EntryPoint = "SetLocaleInfoA")]
public static extern int SetLocaleInfo(int Locale, int dateType, string dateData);
public const int LOCALE_SLONGDATE = 0x20;
public const int LOCALE_SSHORTDATE = 0x1F;
public const int LOCALE_IDATE = 0x21;
public const int LOCALE_ILDATE = 0x22;
这是我设置系统时间的代码 上部分为网上找的(那2个设置长日期,短日期) 可以用
后2句是我查api文档找的(api32) 设置代码如下SetLocaleInfo(i, LOCALE_SSHORTDATE, "yyyy-MM-dd");
SetLocaleInfo(i, LOCALE_SLONGDATE, "yyyy-MM-dd");
SetLocaleInfo(i, LOCALE_IDATE, "HH:mm");
SetLocaleInfo(i, LOCALE_ILDATE, "HH:mm:ss");
多次测试结果表示 我的短日期格式没有设置上去 就是HH:mm系统还是12小时制度 (设置前有获取系统格式 为hh:ss 12小时制,应该为HH 24小时制)是我哪里错了吗? 求大牛..
http://www.geekpedia.com/code117_Get-And-Set-The-System-Date-And-Time.html
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Sample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public struct SystemTime
{
public ushort Year;
public ushort Month;
public ushort DayOfWeek;
public ushort Day;
public ushort Hour;
public ushort Minute;
public ushort Second;
public ushort Millisecond;
};
[DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)]
public extern static void Win32GetSystemTime(ref SystemTime sysTime);
[DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
public extern static bool Win32SetSystemTime(ref SystemTime sysTime);
private void button1_Click(object sender, EventArgs e)
{
// Set system date and time
SystemTime updatedTime = new SystemTime();
updatedTime.Year = (ushort)2008;
updatedTime.Month = (ushort)4;
updatedTime.Day = (ushort)23;
// UTC time; it will be modified according to the regional settings of the target computer so the actual hour might differ
updatedTime.Hour = (ushort)10;
updatedTime.Minute = (ushort)0;
updatedTime.Second = (ushort)0;
// Call the unmanaged function that sets the new date and time instantly
Win32SetSystemTime(ref updatedTime);
// Retrieve the current system date and time
SystemTime currTime = new SystemTime();
Win32GetSystemTime(ref currTime);
// You can now use the struct to retrieve the date and time
MessageBox.Show("It's " + currTime.Hour + " o'clock. Do you know where your C# code is?");
}
}
}
比如结果像是:
2011/7/23
2011-7-23
2011.7.23
2011-07-23
2011/07/23
2011.07.23
11-7-23
11/7/23
11.7.23
11/07/23
2011年7月23日
2011-07-23
星期六, 2011-07-23
星期六, 2011年7月23日
2011年7月23日 19:47
2011年7月23日 19:47
2011年7月23日 下午 7:47
2011年7月23日 下午 07:47
2011-07-23 19:47
2011-07-23 19:47
2011-07-23 下午 7:47
2011-07-23 下午 07:47
星期六, 2011-07-23 19:47
星期六, 2011-07-23 19:47
星期六, 2011-07-23 下午 7:47
星期六, 2011-07-23 下午 07:47
星期六, 2011年7月23日 19:47
星期六, 2011年7月23日 19:47
星期六, 2011年7月23日 下午 7:47
星期六, 2011年7月23日 下午 07:47
2011年7月23日 19:47:41
2011年7月23日 19:47:41
2011年7月23日 下午 7:47:41
2011年7月23日 下午 07:47:41
2011-07-23 19:47:41
2011-07-23 19:47:41
2011-07-23 下午 7:47:41
2011-07-23 下午 07:47:41
星期六, 2011-07-23 19:47:41
星期六, 2011-07-23 19:47:41
星期六, 2011-07-23 下午 7:47:41
星期六, 2011-07-23 下午 07:47:41
星期六, 2011年7月23日 19:47:41
星期六, 2011年7月23日 19:47:41
星期六, 2011年7月23日 下午 7:47:41
星期六, 2011年7月23日 下午 07:47:41
2011/7/23 19:47
2011/7/23 19:47
2011/7/23 下午 7:47
2011/7/23 下午 07:47
2011-7-23 19:47
2011-7-23 19:47
2011-7-23 下午 7:47
2011-7-23 下午 07:47
2011.7.23 19:47
2011.7.23 19:47
2011.7.23 下午 7:47
2011.7.23 下午 07:47
2011-07-23 19:47
2011-07-23 19:47
2011-07-23 下午 7:47
2011-07-23 下午 07:47
2011/07/23 19:47
2011/07/23 19:47
2011/07/23 下午 7:47
2011/07/23 下午 07:47
2011.07.23 19:47
2011.07.23 19:47
2011.07.23 下午 7:47
2011.07.23 下午 07:47
11-7-23 19:47
11-7-23 19:47
11-7-23 下午 7:47
11-7-23 下午 07:47
11/7/23 19:47
11/7/23 19:47
11/7/23 下午 7:47
11/7/23 下午 07:47
11.7.23 19:47
11.7.23 19:47
11.7.23 下午 7:47
11.7.23 下午 07:47
11/07/23 19:47
11/07/23 19:47
11/07/23 下午 7:47
11/07/23 下午 07:47
2011/7/23 19:47:41
2011/7/23 19:47:41
2011/7/23 下午 7:47:41
2011/7/23 下午 07:47:41
2011-7-23 19:47:41
2011-7-23 19:47:41
2011-7-23 下午 7:47:41
2011-7-23 下午 07:47:41
2011.7.23 19:47:41
2011.7.23 19:47:41
2011.7.23 下午 7:47:41
2011.7.23 下午 07:47:41
2011-07-23 19:47:41
2011-07-23 19:47:41
2011-07-23 下午 7:47:41
2011-07-23 下午 07:47:41
2011/07/23 19:47:41
2011/07/23 19:47:41
2011/07/23 下午 7:47:41
2011/07/23 下午 07:47:41
2011.07.23 19:47:41
2011.07.23 19:47:41
2011.07.23 下午 7:47:41
2011.07.23 下午 07:47:41
11-7-23 19:47:41
11-7-23 19:47:41
11-7-23 下午 7:47:41
11-7-23 下午 07:47:41
11/7/23 19:47:41
11/7/23 19:47:41
11/7/23 下午 7:47:41
11/7/23 下午 07:47:41
11.7.23 19:47:41
11.7.23 19:47:41
11.7.23 下午 7:47:41
11.7.23 下午 07:47:41
11/07/23 19:47:41
11/07/23 19:47:41
11/07/23 下午 7:47:41
11/07/23 下午 07:47:41
7月23日
7月23日
2011-07-23T19:47:41.1891545+08:00
2011-07-23T19:47:41.1891545+08:00
Sat, 23 Jul 2011 19:47:41 GMT
Sat, 23 Jul 2011 19:47:41 GMT
2011-07-23T19:47:41
19:47
19:47
下午 7:47
下午 07:47
19:47:41
19:47:41
下午 7:47:41
下午 07:47:41
2011-07-23 19:47:41Z
2011年7月23日 11:47:41
2011年7月23日 11:47:41
2011年7月23日 上午 11:47:41
2011年7月23日 上午 11:47:41
2011-07-23 11:47:41
2011-07-23 11:47:41
2011-07-23 上午 11:47:41
2011-07-23 上午 11:47:41
星期六, 2011-07-23 11:47:41
星期六, 2011-07-23 11:47:41
星期六, 2011-07-23 上午 11:47:41
星期六, 2011-07-23 上午 11:47:41
星期六, 2011年7月23日 11:47:
看看我博客这篇文章 http://blog.csdn.net/fengyarongaa/article/details/6346862
完全实现我的要求?我的要求是修改系统短时间格式 DateTime怎么修改客户系统上的短时间格式?
跑题了
public static DateTime ToDateTime(
string value,
IFormatProvider provider
)可以构造不同的区域以及自定义格式输出时间如果考虑在系统中给DateTime定义扩展方法,效率不会比你调用API慢的
时间格式必须是上面这种,你把时间转成这种就行了,[Time].ToString("yyyy-MM-dd-hh 00:00:00");