如何获取本地时间并将其放在字符串中 [英] how to get local time and put it in a string
本文介绍了如何获取本地时间并将其放在字符串中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个方法 s
作为参数的日期时间。
I have a method s
that has as parameter a date time.
如何写在c ++ ?
在 c#
中是:
string s(System.DateTime sd);
编辑!
如何调用方法?还有我想在一个字符串的小时,在另一个字符串的第二个...等等
EDIT! HOW TO CALL THE S METHOD?! also i would like to have in a string the hour, in another string the second..and so on
另一个问题是:如何转换字符串值的时间具有:日,月,小时,分钟和秒?
Another question is: how to convert the time in a string value that has: day, month, hours, min and seconds ?
推荐答案
google for time.h
下面是伪代码:
Just an example. google for time.h
Below is pseudo code:
#include <time.h>
string getTime ()
{
time_t timeObj;
time(&timeObj);
tm *pTime = gmtime(&timeObj);
char buffer[100];
sprintf(buffer, "%d%d%d", pTime->tm_hour, pTime->tm_min, pTime->tm_sec);
return buffer;
}
这篇关于如何获取本地时间并将其放在字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文