Delphi获得与设置系统时间格式《转》
unit Unit1;
interface
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type TForm1 = class(TForm) btn1: TButton; btn2: TButton; Label1: TLabel; Label2: TLabel; Label3: TLabel; procedure btn1Click(Sender: TObject); procedure btn2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1; GPrevShortDate,GPrevLongDate,GPrevTimeFormat:string; implementation
{$R *.dfm}
procedure GetDateTimeFormat(); const i = 100; var buf:pchar; begin getmem(buf,100); //i:=100; //i必须在调用前赋值为buf缓冲区的长度。如果设为0或负值,将取不到设置的值 GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SSHORTDATE,buf,i); //取当前用户设置,短日期格式。 GPrevShortDate:=string(buf); GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SLONGDATE,buf,i); //取长日期格式 GPrevLongDate:=string(buf); GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_STIMEFORMAT,buf,i); //取时间格式 GPrevTimeFormat:=string(buf); FreeMem(buf); end;
procedure SetDateTimeFormat(); var p:DWORD; begin SetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SSHORTDATE,pchar('yyyy/MM/dd')); //设置短日期格式 SetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SLONGDATE,pchar('yyyy''年''M''月''d''日''')); //设置长日期格式为 yyyy'年'M'月'd'日',“年月日”字符必须用单引号括起来。Delphi字符串里必须用两个单引号。 SetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_STIMEFORMAT,pchar('HH:mm:ss')); //设置时间格式,24小时制 SendMessageTimeOut(HWND_BROADCAST,WM_SETTINGCHANGE,0,0,SMTO_ABORTIFHUNG,10,p);//设置完成后必须调用,通知其他程序格式已经更改,否则即使是程序自身也不能使用新设置的格式 end;
procedure TForm1.btn1Click(Sender: TObject); begin SetDateTimeFormat; ShowMessage('修改成功!'); end;
procedure TForm1.btn2Click(Sender: TObject); begin GetDateTimeFormat(); label1.Caption := GPrevShortDate; Label2.Caption := GPrevLongDate; Label3.Caption := GPrevTimeFormat; ShowMessage('已得到原格式!'); end;
end.
Delphi获得与设置系统时间格式《转》的更多相关文章
- Delphi获取与设置系统时间格式,即GetLocaleInfo和SetLocaleInfo
在Delphi中,特别是在写管理系统软件时,经常要用到 FormatDateTime 以将 TDateTime 格式的日期时间转换成字符串形式的值显示或保存起来,或者用 StrToDateTime将字 ...
- delphi中设置系统时间方法
procedure TMainFrm.Timer1Timer(Sender: TObject); var systemtime:Tsystemtime; dt:TDateTime; begin ...
- date 显示或设置系统时间和日期
显示或设置系统时间和日期 date [options] [+format] date [options] [new date] date用来显示系统的时间和日期,超级用户可以使用date来更改系统时钟 ...
- 将与系统时间格式不同的字符串格式化为DATETIME类型
若系统时间格式为2012/03/05 08:12:12,那么若将("2012-03-05 08:12:12")格式化为时间变量时会报错,在转化之前先将系统时间格式改变再转换就不会报 ...
- QT在linux环境下读取和设置系统时间(通过system来直接调用Linux命令,注意权限问题)
QT在Linux环境下读取和设置系统时间 本文博客链接:http://blog.csdn.NET/jdh99,作者:jdh,转载请注明. 环境: 主机:Fedora12 开发软件:QT 读取系统时间 ...
- date:显示与设置系统时间
功能: date命令用于显示当前的系统时间或设置系统时间 语法格式: date [option] [+format] date [选项] [+日期格式] 参数选项: option 参数选项: -d ...
- linux date 设置系统时间
设置 系统时间 注意时间格式 date -s "date" [root@localhost c]# date -s "2019-05-29 10:58:00" ...
- 5.6 date:显示与设置系统时间
date命令 用于显示当前的系统时间或设置系统时间. date [选项] +[日期格式] date命令的参数选项及说明 OPTION参数选项-d 时间字符串 显示指定字符串所描述的时间,而非当前时 ...
- 使用AIDL调用远程服务设置系统时间
在实际工作中,经常遇到客户需要用代码设置系统时间的需求,但是Android非系统应用是无法设置系统时间的.于是,我设计了一个使用系统签名的时间设置服务,客户通过bind调用服务里的方法就能达到设置时间 ...
随机推荐
- Linux命令之file
file [选项] [文件名] 确认文件类型 (1).常用选项 magic file指的是哪些具有特殊文件格式的文件 -b,--brief 不列出文件名称 -c,--checking-printout ...
- CodeForces - 965E Short Code
Discription Arkady's code contains nn variables. Each variable has a unique name consisting of lower ...
- Codeforces 920 F SUM and REPLACE
Dicription Let D(x) be the number of positive divisors of a positive integer x. For example, D(2) = ...
- 【容斥原理】CDOJ - 1544 - 当咸鱼也要按照基本法
众所周知zhu是一个大厨,zhu一直有自己独特的咸鱼制作技巧. tang是一个咸鱼供应商,他告诉zhu在他那里面有NN条咸鱼(标号从1到N)可以被用来制作. 每条咸鱼都有一个咸鱼值KiKi,初始时所有 ...
- 【莫队算法】【权值分块】poj2104 K-th Number / poj2761 Feed the dogs
先用莫队算法保证在询问之间转移的复杂度,每次转移都需要进行O(sqrt(m))次插入和删除,权值分块的插入/删除是O(1)的. 然后询问的时候用权值分块查询区间k小值,每次是O(sqrt(n))的. ...
- Scala学习总结
1)将Array转化为String,toStrings()方法应该是序列化了的. scala> val args = Array("Hello", "world&q ...
- CHBTC
蛙人高频交易拆单策略-带手续费拆单策略及原理说明 - 王宇 warensoft - 博客园 CHBTC
- springmvc-框架学习
https://www.androiddev.net/springmvc-框架学习一-helloworld/
- lync项目总结
概述 9月份,由于公司人事变动,摆在自己面前也有两条路可选择,一是选择lync,二是选择sharepoint,由于之前,部门老大已经让我看了大概一个月的有关lync方面的资料(文档,代码,项目实施等) ...
- 基于tiny4412的u-boot移植(二)
作者信息 作者:彭东林 邮箱:pengdonglin137@163.com QQ: 405728433 平台介绍 开发环境:win7 64位 + VMware11 + Ubuntu14.04 64位 ...