- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我使用自 1970 年以来的秒(和微秒)以及时区和夏令时标志来表示日期。我想使用 strftime 打印日期表示,但它使用从环境中获取的时区全局值(extern long int timezone)。如何让 strftime 打印我选择的区域?
最佳答案
以下程序使用您所需的时区设置 UNIX 环境变量 TZ,然后使用 strftime 打印格式化时间。
在下面的示例中,时区设置为美国太平洋时区。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main (int argc, char *argv[])
{
struct tm *mt;
time_t mtt;
char ftime[10];
setenv("TZ", "PST8PDT", 1);
tzset();
mtt = time(NULL);
mt = localtime(&mtt);
strftime(ftime,sizeof(ftime),"%Z %H%M",mt);
printf("%s\n", ftime);
}
关于c - 如何在调用 strftime 之前设置时区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1620188/
“strftime”中的“strf”是什么意思?我在谷歌上搜索了很多次这个问题,但没有找到答案。知道这些字母代表什么会让我更容易记住这个函数的名称。 最佳答案 来自 man 3 strftime :
我制作了这个脚本来跟踪我当前的时间和当前的电池百分比(然后将其附加到剪贴板,以便我可以将其粘贴到某个地方): from tkinter import * from urllib import pars
我想从我的 Sqlite 数据库中的日期时间列中获取一个月中的某一天。我可以简单地使用 select strftime('%d',myColumn) from myTable 但是这些值以 UTC 格
我编写了一个 perl 脚本,我在其中调用一个子例程将字段插入到数据库表中。该子例程在除主 perl 文件 Test.pl 之外的另一个文件 Test.pm 中调用。在 Test.pm 中,我将以下字
我们有一个 C++/MFC 应用程序,它允许用户通过配置文件自定义日期格式。不想重新发明轮子,我将格式字符串传递给 CTime::Format("") 以进行实际格式化。在幕后,Format 调用了标
下面列出了两行代码。两者对日期和时间的期望相同,但只有一个有效。我正在使用 R 3.1。 以下不起作用: DateTime2=strftime("08/13/2010 05:26:24.350", f
我使用strftime获得ISO 8601格式(%V)的星期数,并希望转换为前景中显示的星期数(猜测是格里高利历法)。 Outlook日历设置为: 一周的第一天(星期日) 一年的第一周1月1日开始 在
为什么此页面的代码不起作用?:http://strftime.org/ 。我想输出不带前导零的日期和月份,例如 'm/d/yyyy' 例如:“1992 年 4 月 5 日”是 '04/05/1992'
谁能告诉我为什么时区返回为“山区夏令时间”而不是 MST ? import time print time.strftime( "%H:%M %A %Z %d %b %y") 最佳答案 根据您提出的另
我正在尝试更新一些 csv 文件,稍后再更新我的数据库。看来每个月的 strftime 都会混淆一天。我在德国,我们写的是日期 DD/MM/YYYY 而不是 MM/DD/YYYY。 如何从 germa
我当前的计算机显示 CET 时间: $ date Mon Dec 1 21:31:41 CET 2014 但是我的区域设置是 en_US: $ locale | grep -i time LC_TI
strftime('%s', 'now', 'start of month') AND strftime('%s', 'now', 'start of month', '+1 month', '-1
我正在使用以下日期格式: d.strftime("%A, %d %B %Y %H:%m") 并且由于工作日的长度 (%A) 发生了变化,我想总是打印工作日10个字符,左边补空格,右对齐。 有点像 d.
Python3 strftime 产生的结果因平台而异。例如: OS X 10.10.5 >>> sys.version '3.5.2 (v3.5.2:4def2a2901a5, Jun 26 201
大家好,我想知道是否有人可以向我指出这一点。我目前正在尝试在 cmd 提示符的右上角显示日期和时间,但我得到的字符比我要求的要多。这是我目前所拥有的 time_t rawtime; struct tm
#include #include using namespace std; int main() { char dateStringBuffer[256] = ""; tm da
我试过 strftime( ) 来获取格式化的时间戳。 char ft[ 256 ]; struct tm *tmp; strftime( ft, 256, "%D - %T", tmp ); 我的问
char buffer[800]; struct tm str_time; str_time.tm_mday = Cur_Day; str_time.t
例如,时间戳是1403667010.574,使用Time.at(1403667010.574).strftime('%Y-%m-%d %H:%M:%S.%L %z'),则结果为 "2014-06-25
我试图将 YYYY-mm-dd 23:59:59 格式的时间保存到带有日期时间的 mysql 数据库列中。我不明白为什么总是忽略分钟和秒 00 ?非常感谢您的帮助。 PHP: $time = strf
我是一名优秀的程序员,十分优秀!