C#将系统时间转换为double类型

本人是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);
        }

    }
}

  希望大神多多指导

转载于:https://www.cnblogs.com/c150824/p/4764201.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值