标签: ctime

寻找好的FILETIME转换器

问题是寻找好的CTIME/Unix时间转换器我要求基于网络的CTIME(1970年1月1日以来的秒)时间转换器.(通常是32位有符号整数).

我需要一个工具,我可以输入日期,并获得CTIME等效.一旦我意识到Unixtime是该格式的另一个名称,我就能找到一个.一旦到达那里,Google就是我的朋友.

现在怎么样FILETIME转换器,它更常用作64位有符号整数,代表自1601年1月1日以来的100纳秒单位.(Active Directory内部用于时间存储的内容).

可能有一些更好的搜索关键字可以找到它.我有一个工具可以显示我在FILETIME中的当前时间,我可以手动在其他地方进行数学计算,但不是我从易用性方法中看到的.

我有一个可以在代码中使用它的函数,但不是一个能够以快速格式轻松使用的包装器.Java的时间格式化程序支持它,但我再次寻找一个很好的包装版本.

time active-directory ctime

2
推荐指数
1
解决办法
1万
查看次数

使用ctime获取2个操作之间的间隔?

我有兴趣使用ctime在不同的点上显示C中程序的执行时间.我尝试过类似的东西,但一定不对......

int main() {

    time_t tm1, tm2;
    tm1 = time(NULL);
    sleep(2);
    tm2 = ctime(tm1);

    printf("%d\n", tm2-tm1);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

你有什么建议或正确的例子吗?提前致谢

c ctime

2
推荐指数
1
解决办法
3218
查看次数

如何在c ++中选择随机字母

嗨,我正在为我的c ++课程中的最后一个刽子手项目工作.我已经完成了大部分工作,但我想做到这一点,所以玩家可以选择在单人模式下对抗电脑对手.我尝试做类似97 + rand()%123之类的东西,然后将数字转换为字符,但我一直在变得怪异的字符,比如颠倒了我检查一下,看看我是否遗漏了一些东西,但我有正确的指令,我加入了一个srand .我所做的简化版看起来像这样

#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;

int main(){
    char cch;
    char ch; 
    unsigned seed= time(0)
    srand(seed)
    cch=97rand()%123;
    ch=cch;
    cout<<"computer chose "<< ch<<endl;
}
Run Code Online (Sandbox Code Playgroud)

请注意,我没有包括我的项目的所有内容

c++ arrays random ctime

2
推荐指数
3
解决办法
3万
查看次数

在C++中将系统日期和时间作为文件名传递

我想建立一个考勤系统,它将系统日期和时间作为文件的文件名,例如:这是通常的情况.

int main () {
time_t t = time(0);   // get time now
struct tm * now = localtime( & t );
cout << (now->tm_year + 1900) << '-'
     << (now->tm_mon + 1) << '-'
     <<  now->tm_mday
     << endl;
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
} 
Run Code Online (Sandbox Code Playgroud)

但我希望系统日期和时间代替example.txt我通过在上面的程序中包含ctime头文件来计算时间只是示例.

c++ fstream ctime

2
推荐指数
1
解决办法
1万
查看次数

如何将字符串解析为ctime结构?

是否存在将字符串解析为Time结构的既定方法?

我理想的做法是反过来strftime(...),而不是从时间结构和格式字符串生成字符串,我从根据提供的格式字符串解析的字符串中获取时间结构.

我不希望通过包含一个DateTime类来增加额外的开销,例如在Boost或.NET中找到的类

c c++ time strftime ctime

1
推荐指数
1
解决办法
2426
查看次数

使用ctime和time_t输出差异

发现一个奇怪的差异输出time_t通过ctime同时搞乱计时和持续时间.我绝对错过了这里的一些东西.在代码和输出之后有关于该问题的更多信息.我搜索了一下类似的问题,如果有的话请指导我.

我目前正在运行:操作系统:Windows 7 64位CPU:Intel Core i5 M 520 2.40Ghz RAM:4GB IDE:Microsoft Visual Studio Express 2013

编辑:完整来源

#include <iostream>
#include <chrono>
#include <ctime>
#include <thread>

using namespace std::chrono;

int main()
{
    duration<int, std::milli> wait(5500);

    time_point<system_clock>  timePoint_Start;
    time_point<system_clock>  timePoint_End;
    time_t                    timeT_Start;
    time_t                    timeT_End;

    std::cout << "01. timePoint_Start Address, sizeof: " << &timePoint_Start << ", " << sizeof(timePoint_Start) << std::endl; 
    std::cout << "02. timePoint_End   Address, sizeof: " << &timePoint_End   << ", " << sizeof(timePoint_End)   << std::endl;
    std::cout << "03. timeT_Start     Address, sizeof: " …
Run Code Online (Sandbox Code Playgroud)

c++ duration ctime c++11 output

1
推荐指数
1
解决办法
133
查看次数

ctime返回null

如果用户类型time_t定义为__darwin_time_t,其本身long在MacOS X中定义,为什么以下代码输出8 Time is (null)?也许这是愚蠢的事,但我无法理解它.

#include <stdio.h>
#include <time.h>

int main(void)
{
    time_t time = 0x7FFFFFFFFFFFFFFF;

    printf("%lu\n"
           "Time is %s\n", sizeof(time_t), ctime(&time));

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c macos time x86-64 ctime

0
推荐指数
1
解决办法
1978
查看次数

使用time()函数计算执行时间

我获得了以下HomeWork任务,

编写一个程序,在你的计算机上测试nlogn,n2,n5,2n和n需要多长时间!n = 5,10,15,20的加法.

我写了一段代码但是我一直都在执行时间.有人可以帮我解决吗?谢谢

#include <iostream>
#include <cmath>
#include <ctime>
using namespace std;
int main()
{
 float n=20;
 time_t start, end, diff;
  start = time (NULL);
  cout<<(n*log(n))*(n*n)*(pow(n,5))*(pow(2,n))<<endl;
  end= time(NULL);
 diff = difftime (end,start);
 cout <<diff<<endl;
 return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ time ctime

0
推荐指数
1
解决办法
2万
查看次数

调用'localtime_s'时日历函数崩溃

我正在尝试创建一个callendar,所以我使用time_t和localtime_s来存储时间和日期信息,然后将它存储在Calendar类的各个成员中:

void Callendar::Initialize()
{
    time_t now = time(0);
    tm *localTime = null;
    localtime_s(localTime, &now);

    LocalSeconds = localTime->tm_sec;
    LocalMinutes = localTime->tm_min;
    LocalHours = localTime->tm_hour;
    LocalDays = localTime->tm_mday;
    LocalMonths = localTime->tm_mon;
    LocalYears = localTime->tm_year;
    DaysSinceSunday = localTime->tm_wday;
    DaysSinceJanuaryFirst = localTime->tm_yday;
    HoursDaylightSavings = localTime->tm_isdst;
}
Run Code Online (Sandbox Code Playgroud)

所有编译都很好,但在运行时我得到:

调试断言失败!

程序:C:\ Users\MyPC\Desktop\Framework\Framework\Debug\Framework.exe文件:f:\ dd\vctools\crt_bld\self_x86\crt\src\loctim64.c行:69

表达式:(ptm!= NULL)

关闭失败的断言消息后,我在此行收到一个标准的调试错误:

static __inline errno_t __CRTDECL localtime_s(struct tm * _Tm, const time_t * _Time)
{
    return _localtime64_s(_Tm, _Time);
}
Run Code Online (Sandbox Code Playgroud)

这基本上是调用*localtime_s(localTime,&now);*在Calendar:Initialize()中的结果 我可以使用这个功能的弃用版本吗?我知道还有其他函数可以获取本地时间,但我不知道哪个其中一个是"正确"的.其他人向我建议我不应该使用'localtime',但看起来localtime_s也没有用.

c++ debugging ctime localtime

0
推荐指数
1
解决办法
2163
查看次数

C++ 11 chrono有哪些替代方案?

我正在运行我的下面代码,检查是否data_timestamp超过两周.如果它超过两周,则打印hello否则打印world.

我是一名Java开发人员,最近开始使用C++.通过互联网学到了一些东西,所以我在这个程序中使用它.我没有意识到并非所有代码都可以使用C++ 11功能运行.

#include <ctime>
#include <chrono>
#include <iostream>

int main()
{

    uint64_t data_timestamp = 1406066507000; 

    const auto now = std::chrono::system_clock::now();
    auto twoWeeks = std::chrono::hours(24 * 14);
    auto lastTwoWeeks = now - twoWeeks;

    auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(lastTwoWeeks.time_since_epoch()).count();

    std::cout << "Time stamp in milliseconds since UNIX epoch start: "<< millis << std::endl;

    if (data_timestamp < millis) { 
        std::cout << "Hello"; 
    } else { 
        std::cout << "World"; 
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

目前上面的代码使用C++ 11功能,但我使用上面两周时间戳代码逻辑的实际代码不支持C++ 11所以我正在寻找各种替代方案.

我还能在这里使用哪些不需要C++ 11的可移植性?我可以使用 …

c++ boost ctime c++11

0
推荐指数
1
解决办法
1882
查看次数

为什么rand()给出了我定义的间隔之外的数字?(昨天工作正常)

我生成1000和11000之间的随机整数.但它们必须具有6000的平均值.我昨天在我的程序中使用了这段代码并且它运行得很好,但现在它给了我很大的数字,好像我的间隔没有物.

编辑:将代码删除一点以便于阅读.

srand(time(NULL));
int k = 5;
int cTotal = 0;
int cAverage = 0;

  struct process {
    int pid; // process id
    int cycles; // number of cycles required to complete the process
    int mSize; // size of the memory footprint
};

    for (int i = 0; i < k; i++) {

        processes[i].pid = i; // set the unique identifier of the process.

        // If statements for determining the number cycles in each process
        if (k == 0) { …
Run Code Online (Sandbox Code Playgroud)

c++ random ctime

0
推荐指数
1
解决办法
67
查看次数

标签 统计

ctime ×11

c++ ×8

time ×4

c ×3

c++11 ×2

random ×2

active-directory ×1

arrays ×1

boost ×1

debugging ×1

duration ×1

fstream ×1

localtime ×1

macos ×1

output ×1

strftime ×1

x86-64 ×1