[DllImport("kernel32.dll", EntryPoint = "GetSystemDefaultLCID")]
public static extern int GetSystemDefaultLCID();
[DllImport("kernel32.dll", EntryPoint = "SetLocaleInfoA")]
public static extern int SetLocaleInfo(int Locale, int LCType, string lpLCData); public const int LOCALE_SSHORTDATE = 0x1F;
public static void SetTimeForMat()
{
try
{
//读写注册表 int x = GetSystemDefaultLCID();
SetLocaleInfo(x, LOCALE_SSHORTDATE, "yyyy-MM-dd"); //短日期格式
}
catch
{ }
}为什么程序中datetimepicker控件的显示还是没变?
解决方案 »
- DropDownList 我加了JS的onchange事件后.为什么不执行SelectedIndexChanged后台事件了??
- 在线等待-------------------------求解编码!
- 如何实现运行窗体后让按钮上的字体一直随即变换颜色
- 新手用SharpDevelop出现的问题???
- DataGrid 的 !IsPostBack 问题
- 怎麽用C#在WinForm上寫一 倒立的字
- checkedListBox怎样邦定隐藏值
- linq where 00开头的字符串
- c# 设置excel图表x轴字体纵向显示并让图表和数据在同一个sheet里显示
- 如何越级调用虚函数?
- 需要个第三方控件
- 初学者请教一个问题
using System.Runtime.InteropServices;
//api函数声明
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool SetSystemTime(ref SYSTEMTIME time);
public struct SYSTEMTIME
{
public short Year;
public short Month;
public short DayOfWeek;
public short Day;
public short Hour;
public short Minute;
public short Second;
public short Milliseconds;
}
private void Setdatetime()
{
//调用代码
DateTime idag = new DateTime((int)DateTime.Now.AddYears(1).Year,//增加年
(int)DateTime.Now.AddMonths(0).Month,//增加月
(int)DateTime.Now.AddDays(0).Day,//增加天
(int)(DateTime.Now.AddHours(0).Hour),//增加小时
(int)(DateTime.Now.AddMinutes(0).Minute),//增加分
(int)(DateTime.Now.AddSeconds(0).Second),//增加秒
DateTimeKind.Local);
SYSTEMTIME s = new SYSTEMTIME();
s.Year = (short)idag.Year;
s.Month = (short)idag.Month;
s.DayOfWeek = (short)idag.DayOfWeek;
s.Day = (short)idag.Day;
s.Hour = (short)idag.Hour;
s.Minute = (short)idag.Minute;
s.Second = (short)idag.Second;
s.Milliseconds = (short)idag.Millisecond;
bool v= SetSystemTime(ref s);
Console.WriteLine(v.ToString());
} //修改系统时间用Datetime.Now获取没问题
这么多够吗?
//获取日期+时间
DateTime.Now.ToString(); // 2008-9-4 20:02:10
DateTime.Now.ToLocalTime().ToString(); // 2008-9-4 20:12:12//获取日期
DateTime.Now.ToLongDateString().ToString(); // 2008年9月4日
DateTime.Now.ToShortDateString().ToString(); // 2008-9-4
DateTime.Now.ToString("yyyy-MM-dd"); // 2008-09-04
DateTime.Now.Date.ToString(); // 2008-9-4 0:00:00//获取时间
DateTime.Now.ToLongTimeString().ToString(); // 20:16:16
DateTime.Now.ToShortTimeString().ToString(); // 20:16
DateTime.Now.ToString("hh:mm:ss"); // 08:05:57
DateTime.Now.TimeOfDay.ToString(); // 20:33:50.7187500//其他
DateTime.ToFileTime().ToString(); // 128650040212500000
DateTime.Now.ToFileTimeUtc().ToString(); // 128650040772968750
DateTime.Now.ToOADate().ToString(); // 39695.8461709606
DateTime.Now.ToUniversalTime().ToString(); // 2008-9-4 12:19:14DateTime.Now.Year.ToString(); 获取年份 // 2008
DateTime.Now.Month.ToString(); 获取月份 // 9
DateTime.Now.DayOfWeek.ToString(); 获取星期 // Thursday
DateTime.Now.DayOfYear.ToString(); 获取第几天 // 248
DateTime.Now.Hour.ToString(); 获取小时 // 20
DateTime.Now.Minute.ToString(); 获取分钟 // 31
DateTime.Now.Second.ToString(); 获取秒数 // 45