zoukankan      html  css  js  c++  java
  • 个人笔记

    1. 2011年3月1日14:15:59

    ((DateTime)dr["Data_time"]).ToShortTimeString();
    "10:31"
    ((DateTime)dr["Data_time"]).ToLongTimeString();
    "10:31:48"
    ((DateTime)dr["Data_time"]).ToShortDateString();
    "2010-8-17"
    ((DateTime)dr["Data_time"]).ToLongDateString();
    "2010年8月17日"
    ((DateTime)dr["Data_time"]).ToString()
    "2010-8-17 10:31:48"

    2.获取、修改系统时间,获取磁盘序列号

    原文:http://www.cnblogs.com/cnlan/archive/2010/01/22/1654295.html

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;

    namespace Fengyun
    {
        
    public class Win32
        {
            
    #region 修改本地系统时间
            [DllImport(
    "Kernel32.dll")]
            
    private extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);

            [DllImport(
    "Kernel32.dll")]
            
    private extern static uint SetLocalTime(ref SYSTEMTIME lpSystemTime);

            [StructLayout(LayoutKind.Sequential)]
            
    private struct SYSTEMTIME
            {
                
    public ushort wYear;
                
    public ushort wMonth;
                
    public ushort wDayOfWeek;
                
    public ushort wDay;
                
    public ushort wHour;
                
    public ushort wMinute;
                
    public ushort wSecond;
                
    public ushort wMilliseconds;
            }

            
    /// <summary>
            
    /// 将本地时间与sqlserver服务器时间同步
            
    /// </summary>
            
    /// <param name="SqlServerTime">时间</param>
            public static void SetTime(DateTime SqlServerTime)
            {
                SYSTEMTIME st 
    = new SYSTEMTIME();
                st.wYear 
    = Convert.ToUInt16(SqlServerTime.Year);
                st.wMonth 
    = Convert.ToUInt16(SqlServerTime.Month);
                st.wDay 
    = Convert.ToUInt16(SqlServerTime.Day);
                st.wHour 
    = Convert.ToUInt16(SqlServerTime.Hour);
                st.wMilliseconds 
    = Convert.ToUInt16(SqlServerTime.Millisecond);
                st.wMinute 
    = Convert.ToUInt16(SqlServerTime.Minute);
                st.wSecond 
    = Convert.ToUInt16(SqlServerTime.Second);
                SetLocalTime(
    ref st);
            }
            
    #endregion

            
    #region 获取硬盘序列号

            [DllImport(
    "kernel32.dll")]
            
    private static extern int GetVolumeInformation(
            
    string lpRootPathName,
            
    string lpVolumeNameBuffer,
            
    int nVolumeNameSize,
            
    ref int lpVolumeSerialNumber,
            
    int lpMaximumComponentLength,
            
    int lpFileSystemFlags,
            
    string lpFileSystemNameBuffer,
            
    int nFileSystemNameSize
            );

            
    /// <summary>
            
    /// 获取硬盘序列号
            
    /// </summary>
            
    /// <param name="drvID">硬盘盘符[c|d|e|....]</param>
            
    /// <returns></returns>
            public static string GetDiskVolume(string drvID)
            {
                
    const int MAX_FILENAME_LEN = 256;
                
    int retVal = 0;
                
    int lpMaximumComponentLength = 0;
                
    int lpFileSystemFlags = 0;
                
    string lpVolumeNameBuffer = null;
                
    string lpFileSystemNameBuffer = null;


                
    int i = GetVolumeInformation(
                drvID 
    + @":\",
                lpVolumeNameBuffer,
                MAX_FILENAME_LEN,
                
    ref retVal,
                lpMaximumComponentLength,
                lpFileSystemFlags,
                lpFileSystemNameBuffer,
                MAX_FILENAME_LEN
                );

                
    return retVal.ToString("x");
            }

            
    #endregion
        }
    }

  • 相关阅读:
    GIT 基本语句
    SpringBoot查看哪些配置类自动生效
    LeetCode第一题 两数之和
    static{} java中的静态代码块
    mybatis引入mapper映射文件的4种方法(转)
    MySQL Charset/Collation(字符集/校对)(转)
    MySQL数据库的创建(详细)
    Eclipse出现Tomcat无法启动:Server Tomcat v8.5 Server at localhost failed to start问题
    判断一个int类型数字的奇偶性
    linux中安装erlang时使用make命令报错问题
  • 原文地址:https://www.cnblogs.com/ColdFish_Pegasus/p/1967956.html
Copyright © 2011-2022 走看看