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获得与设置系统时间格式《转》的更多相关文章

  1. Delphi获取与设置系统时间格式,即GetLocaleInfo和SetLocaleInfo

    在Delphi中,特别是在写管理系统软件时,经常要用到 FormatDateTime 以将 TDateTime 格式的日期时间转换成字符串形式的值显示或保存起来,或者用 StrToDateTime将字 ...

  2. delphi中设置系统时间方法

    procedure TMainFrm.Timer1Timer(Sender: TObject); var   systemtime:Tsystemtime;   dt:TDateTime; begin ...

  3. date 显示或设置系统时间和日期

    显示或设置系统时间和日期 date [options] [+format] date [options] [new date] date用来显示系统的时间和日期,超级用户可以使用date来更改系统时钟 ...

  4. 将与系统时间格式不同的字符串格式化为DATETIME类型

    若系统时间格式为2012/03/05 08:12:12,那么若将("2012-03-05 08:12:12")格式化为时间变量时会报错,在转化之前先将系统时间格式改变再转换就不会报 ...

  5. QT在linux环境下读取和设置系统时间(通过system来直接调用Linux命令,注意权限问题)

    QT在Linux环境下读取和设置系统时间 本文博客链接:http://blog.csdn.NET/jdh99,作者:jdh,转载请注明. 环境: 主机:Fedora12 开发软件:QT 读取系统时间 ...

  6. date:显示与设置系统时间

    功能: date命令用于显示当前的系统时间或设置系统时间 语法格式: date [option] [+format] date [选项] [+日期格式] 参数选项: option 参数选项: -d  ...

  7. linux date 设置系统时间

    设置 系统时间 注意时间格式 date  -s "date" [root@localhost c]# date -s "2019-05-29 10:58:00" ...

  8. 5.6 date:显示与设置系统时间

    date命令 用于显示当前的系统时间或设置系统时间. date [选项] +[日期格式]   date命令的参数选项及说明 OPTION参数选项-d 时间字符串 显示指定字符串所描述的时间,而非当前时 ...

  9. 使用AIDL调用远程服务设置系统时间

    在实际工作中,经常遇到客户需要用代码设置系统时间的需求,但是Android非系统应用是无法设置系统时间的.于是,我设计了一个使用系统签名的时间设置服务,客户通过bind调用服务里的方法就能达到设置时间 ...

随机推荐

  1. [BZOJ3816][清华集训2014]矩阵变换(稳定婚姻问题)

    3816: 矩阵变换 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 803  Solved: 578[Submit][Status][Discuss] ...

  2. HDOJ 2582 f(n)

    Discription This time I need you to calculate the f(n) . (3<=n<=1000000) f(n)= Gcd(3)+Gcd(4)+… ...

  3. 【博弈论】【SG函数】bzoj3404 [Usaco2009 Open]Cow Digit Game又见数字游戏

    #include<cstring> #include<cstdio> #include<algorithm> #include<set> using n ...

  4. [CSAcademy]Connected Tree Subgraphs

    题目大意: 给你一棵n个结点的树,求有多少种染色方案,使得染色过程中染过色的结点始终连成一块. 思路: 树形DP. 设f[x]表示先放x时,x的子树中的染色方案数,y为x的子结点. 则f[x]=pro ...

  5. 洛谷 P2066 机器分配

     题目背景 Background 无  题目描述 Description 总公司拥有高效设备M台,准备分给下属的N个分公司.各分公司若获得这些设备,可以为国家提供一定的盈利.问:如何分配这M台设备才能 ...

  6. 生成唯一code

    private String getCode() { List<String> ptypeCodeList = mapper.findCodeList(); String code = & ...

  7. Looking deeper into SQL Server using Minidumps

    https://blogs.msdn.microsoft.com/sqlcat/2009/09/11/looking-deeper-into-sql-server-using-minidumps/ A ...

  8. 获取配置文件中的key的value

    获取App.config文件的key的value System.Configuration.ConfigurationManager.AppSettings["keyName"] ...

  9. [Android Pro] 通过Android trace文件分析死锁ANR

    转载自: http://blog.csdn.net/oujunli/article/details/9102101#reply 对于从事Android开发的人来说,遇到ANR(Application ...

  10. nagios学习记录

    这几天开始接触nagios,记录下学习的心得 监控机上需要安装nagios,nagios-plugins, nrpe 被监控机上需要安装nagios-plugins, nrpe nagios通过插件n ...