本人是C#新手,希望各位大神多多关照。
今天下午为了这个问题 , 苦恼了半天。
现将源码贴出来
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SYSTEMTIME sm = new SYSTEMTIME
{
wYear = 2015,
wMonth = 8,
wDay = 27,
wHour = 11,
wMinute = 53,
wMilliseconds = 0
};
double t;
NativeMethods.SystemTimeToVariantTime(ref sm, out t);
Console.WriteLine(t);
Console.ReadKey(true);
}
[StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct SYSTEMTIME
{
/// WORD->unsigned short
public ushort wYear;
/// WORD->unsigned short
public ushort wMonth;
/// WORD->unsigned short
public ushort wDayOfWeek;
/// WORD->unsigned short
public ushort wDay;
/// WORD->unsigned short
public ushort wHour;
/// WORD->unsigned short
public ushort wMinute;
/// WORD->unsigned short
public ushort wSecond;
/// WORD->unsigned short
public ushort wMilliseconds;
}
public class NativeMethods
{
/// Return Type: INT->int
///lpSystemTime: LPSYSTEMTIME->_SYSTEMTIME*
///pvtime: DOUBLE*
[DllImportAttribute("OleAut32.dll", EntryPoint = "SystemTimeToVariantTime")]
public static extern int SystemTimeToVariantTime(ref SYSTEMTIME lpSystemTime, out double pvtime);
}
}
}
希望大神多多指导