time_t和SYSTEMTIME之间的相互转换 【转】

time_t和SYSTEMTIME之间的相互转换

#include <ctime>

/*

**time_t转SYSTEMTIME

*/

SYSTEMTIME TimetToSystemTime(time_t t)

{

FILETIME ft;

SYSTEMTIME pst;

LONGLONG nLL = Int32x32To64(t, 10000000) + 116444736000000000;

ft.dwLowDateTime = (DWORD)nLL;

ft.dwHighDateTime = (DWORD)(nLL >> 32);

FileTimeToSystemTime(&ft, &pst);

return pst;

}

/*

**SYSTEMTIME转time_t

*/

time_t SystemTimeToTimet(SYSTEMTIME st)

{

FILETIME ft;

SystemTimeToFileTime( &st, &ft );

LONGLONG nLL;

ULARGE_INTEGER ui;

ui.LowPart = ft.dwLowDateTime;

ui.HighPart = ft.dwHighDateTime;

nLL = (ft.dwHighDateTime << 32) + ft.dwLowDateTime;

time_t pt = (long)((LONGLONG)(ui.QuadPart - 116444736000000000) / 10000000);

return pt;

}

/*

**time_t转SYSTEMTIME

*/

SYSTEMTIME Time_tToSystemTime(time_t t)

{

tm temptm = *localtime(&t);

SYSTEMTIME st = {1900 + temptm.tm_year,

1 + temptm.tm_mon,

temptm.tm_wday,

temptm.tm_mday,

temptm.tm_hour,

temptm.tm_min,

temptm.tm_sec,

0};

return st;

}

/*

**SYSTEMTIME转time_t

*/

time_t SystemTimeToTime_t( const SYSTEMTIME& st )

{

tm temptm = {st.wSecond,

st.wMinute,

st.wHour,

st.wDay,

st.wMonth - 1,

st.wYear - 1900,

st.wDayOfWeek,

0,

0};

return mktime(&temptm);

}

时间: 2024-08-05 12:04:33

time_t和SYSTEMTIME之间的相互转换 【转】的相关文章

C#List&lt;string&gt;和string[]之间的相互转换

 一.LIST概述 所属命名空间:System.Collections.Generic      public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable List<T>类是 ArrayList 类的泛型等效类.该类使用大小可按需动态增加的数组实现 IList<T> 泛型接口.  泛型的好处: 它为使

XML编程总结(六)——使用JAXB进行java对象和xml格式之间的相互转换

(六)使用JAXB进行java对象和xml格式之间的相互转换 JAXB能够使用Jackson对JAXB注解的支持实现(jackson-module-jaxb-annotations),既方便生成XML,也方便生成JSON,这样一来可以更好的标志可以转换为JSON对象的JAVA类. JAXB(Java Architecture for XML Binding) 是一个业界的标准,是一项可以根据XML Schema产生Java类的技术.该过程中,JAXB也提供了将XML实例文档反向生成Java对象树

Python网络编程——主机字节序和网络字节序之间的相互转换

If you ever need to write a low-level network application, it may be necessary to handle the low-level data transmission over the wire between two machines. This operation requires some sort of conversion of data from the native host operating system

java Data、String、Long三种日期类型之间的相互转换

java Data.String.Long三种日期类型之间的相互转换 // date类型转换为String类型 // formatType格式为yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日 HH时mm分ss秒 // data Date类型的时间 public static String dateToString(Date data, String formatType) { return new SimpleDateFormat(formatType).format(data

C# Enum Name String Description之间的相互转换

最近工作中经常用到Enum中Value.String.Description之间的相互转换,特此总结一下. 1.首先定义Enum对象 1 public enum Weekday 2 { 3 [Description("星期一")] 4 Monday=1, 5 [Description("星期二")] 6 Tuesday=2, 7 [Description("星期三")] 8 Wednesday=3, 9 [Description("星期

Byte[]、Image、Bitmap 之间的相互转换

原文:Byte[].Image.Bitmap 之间的相互转换 /// <summary>        /// 将图片Image转换成Byte[]        /// </summary>        /// <param name="Image">image对象</param>        /// <param name="imageFormat">后缀名</param>        

char * string nsstring 之间的相互转换

std::string转NSString std::string _string("hello"); NSString *str= [NSString stringWithCString:_string.c_str() encoding:[NSString defaultCStringEncoding]]; NSString转std::string NSString * nsfaceName[email protected]"HELLO"; const char *

PInvoke复习之深入理解char*与wchar_t*与string以及wstring之间的相互转换

本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下  #ifndef USE_H_       #define USE_H_       #include <iostream>       #include <windows.h>       #include <string>       using namespace std;       class CUser       {  

深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换 [转]

本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下. 1 #ifndef USE_H_ 2 #define USE_H_ 3 4 #include <iostream> 5 #include <windows.h> 6 #include <string> 7 using namespace std; 8 class CUser 9 { 10 public: 11 CUser(); 12