當前位置: 首頁>>代碼示例>>C#>>正文


C# DateTime.ToBinary方法代碼示例

本文整理匯總了C#中System.DateTime.ToBinary方法的典型用法代碼示例。如果您正苦於以下問題:C# DateTime.ToBinary方法的具體用法?C# DateTime.ToBinary怎麽用?C# DateTime.ToBinary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.DateTime的用法示例。


在下文中一共展示了DateTime.ToBinary方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ToBinary

        public void ToBinary()
        {
            DateTime d1 = new DateTime(2009, 1, 4);
            var a = d1.ToBinary();
            var b = DateTimeExtensions.ToBinary(d1);
            Assert.AreEqual(a, b);

            d1 = new DateTime(2008, 6, 19);
            a = d1.ToBinary();
            b = DateTimeExtensions.ToBinary(d1);
            Assert.AreEqual(a, b);

            d1 = new DateTime(2008, 6, 19, 0, 0, 0, DateTimeKind.Utc);
            a = d1.ToBinary();
            b = DateTimeExtensions.ToBinary(d1);
            Assert.AreEqual(a, b);

            d1 = DateTime.Now;
            a = d1.ToBinary();
            b = DateTimeExtensions.ToBinary(d1);
            Assert.AreEqual(a, b);

            d1 = DateTime.UtcNow;
            a = d1.ToBinary();
            b = DateTimeExtensions.ToBinary(d1);
            Assert.AreEqual(a, b);

            d1 = DateTime.Today;
            a = d1.ToBinary();
            b = DateTimeExtensions.ToBinary(d1);
            Assert.AreEqual(a, b);
        }
開發者ID:modulexcite,項目名稱:LoreSoft.Shared,代碼行數:32,代碼來源:DateTimeTests.cs

示例2: GetFullSessionID

 /// <summary>
 /// Generates a shared session ID
 /// </summary>
 /// <param name="serverId">The server ID</param>
 /// <param name="sessionId">The session ID</param>
 /// <param name="sessionTimestamp">The session data timestamp</param>
 /// <returns>A well-formated shared session ID</returns>
 public static string GetFullSessionID(string serverId, string sessionId, DateTime sessionTimestamp)
 {
     return String.Format("{0}/{1}/{2}",
         sessionId,
         serverId,
         sessionTimestamp.ToBinary());
 }
開發者ID:rrdiaz,項目名稱:MongoDBSharedSession,代碼行數:14,代碼來源:SharedSessionIDManager.cs

示例3: CreateDefaultPref

    public void CreateDefaultPref()
    {
        PlayerPrefs.SetInt("GamePlayCount", GamePlayCount);
        PlayerPrefs.SetInt("TotalCoins", GameGlobalVariablesManager.InitCoins);
        PlayerPrefs.SetInt("TotalCrystals", TotalCrystals);
        PlayerPrefs.SetInt("EnergyAvailable", GameGlobalVariablesManager.InitEnergyAvailable);
        PlayerPrefs.SetInt("PlayerLevel", GameGlobalVariablesManager.PlayerLevel);
        PlayerPrefs.SetInt("SwordLevel", GameGlobalVariablesManager.SwordLevel);
        PlayerPrefs.SetInt("ArmorLevel", GameGlobalVariablesManager.ArmorLevel);
        PlayerPrefs.SetInt("KnifeCount", GameGlobalVariablesManager.InitKnifeCount);
        PlayerPrefs.SetInt("BombsCount", GameGlobalVariablesManager.InitBombsCount);
        PlayerPrefs.SetInt("CycloneCount", GameGlobalVariablesManager.InitCycloneCount);
        PlayerPrefs.SetInt("LevelsCleared", GameGlobalVariablesManager.InitLevelsCleared);

        currentDate = System.DateTime.Now;
        LastSavedTime = currentDate.ToBinary().ToString();
        LastDailyBonusTime = LastSavedTime;
        LastEnergyBonusTime = LastSavedTime;
        PlayerPrefs.SetString("LastSavedTime", LastSavedTime);
        PlayerPrefs.SetString("FirstDailyBonusTime", LastSavedTime);
        PlayerPrefs.SetString("LastDailyBonusTime", LastDailyBonusTime);
        PlayerPrefs.SetString("LastEnergyBonusTime", LastEnergyBonusTime);
        PlayerPrefs.SetInt("DayCount", DayCount);

        PlayerPrefs.Save();
    }
開發者ID:Skytou,項目名稱:Project-P,代碼行數:26,代碼來源:SavedData.cs

示例4: DeleteInactiveProfiles

        public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
        {
            var connection = GetConnection();
            var min = (double)userInactiveSinceDate.ToBinary();
            const double max = double.MaxValue;
            var key = string.Empty;
            switch (authenticationOption)
            {
                case ProfileAuthenticationOption.All:
                    key = GetProfilesKey();
                    break;
                case ProfileAuthenticationOption.Anonymous:
                    key = GetProfilesKeyAnonymous();
                    break;
                case ProfileAuthenticationOption.Authenticated:
                    key = GetProfilesKeyAuthenticated();
                    break;
            }

            var inactiveUsersTask = connection.SortedSets.Range(_redisDb, key, min, max);
            var inactiveUsers = connection.Wait(inactiveUsersTask);
            var count = 0;

            Parallel.ForEach(inactiveUsers, result =>
            {
                var profileResult = new string(Encoding.Unicode.GetChars(result.Key));
                var parts = profileResult.Split(':');
                var username = parts[0];
                var isAuthenticated = Convert.ToBoolean(parts[1]);
                if (DeleteProfile(username, isAuthenticated))
                    Interlocked.Increment(ref count);
            });

            return count;
        }
開發者ID:kylesonaty,項目名稱:AspNetRedisProviders,代碼行數:35,代碼來源:RedisProfileProvider.cs

示例5: Generate

 public static VerificationToken Generate(DateTime timestamp)
 {
     var data = new byte[DataLength];
     new RNGCryptoServiceProvider().GetBytes(data);
     Array.Copy(BitConverter.GetBytes(timestamp.ToBinary()), data, sizeof(long));
     return new VerificationToken(data);
 }
開發者ID:Sinbadsoft,項目名稱:Sinbadsoft.Lib.UserManagement,代碼行數:7,代碼來源:VerificationToken.cs

示例6: TimeSpanDefinition

        /// <summary>
        /// Creates a new timespan definition
        /// </summary>
        /// <param name="myFrom">The point in time where the timespan begins</param>
        /// <param name="myTo">The point in time where the timespan ends</param>
        public TimeSpanDefinition(DateTime myFrom, DateTime myTo)
        {
            From = myFrom;
            _fromConverted = From.ToBinary();

            To = myTo;
            _toConverted = To.ToBinary();
        }
開發者ID:anukat2015,項目名稱:sones,代碼行數:13,代碼來源:TimeSpanDefinition.cs

示例7: LogPath

        static string LogPath(string appPath, DateTime now)
        {
            if (string.IsNullOrEmpty(appPath)) throw new ArgumentNullException("appPath");

            var logPath = Path.GetFullPath(Path.Combine(appPath, @"..\Private\Logs\Exceptions\", now.ToString("yy-MM-dd")));
            Directory.CreateDirectory(logPath);
            return Path.Combine(logPath, now.ToBinary() + ".xml");
        }
開發者ID:maxime-paquatte,項目名稱:MultiRando,代碼行數:8,代碼來源:ExceptionLoggerService.cs

示例8:

 void IArchByteBoxWriter.wDateTime(DateTime DT, bool isBinary)
 {
     byte[] @Byte = null;
     if (isBinary)
         @Byte = BitConverter.GetBytes(DT.ToBinary());
     else
         @Byte = BitConverter.GetBytes(DT.Ticks);
     nMStream.Write(@Byte, 0, @Byte.Length);
 }
開發者ID:AnotherAltr,項目名稱:Rc.Core,代碼行數:9,代碼來源:ArchMBWriter.cs

示例9: CheckThrowDatePriorToLast

		protected void CheckThrowDatePriorToLast(DateTime appending) {
			if (this.DateTimes.Count == 0) return;
			DateTime lastDateTime = this.LastStaticDate;
			if (lastDateTime.ToBinary() < appending.ToBinary()) return;

			string msg = "#3 Can not append time[" + appending + "] should be > this.Date["
				+ (this.DateTimes.Count - 1) + "]=[" + lastDateTime + "]";
			throw new Exception(msg);
		}
開發者ID:sanyaade-fintechnology,項目名稱:SquareOne,代碼行數:9,代碼來源:DataSeriesTimeBased.cs

示例10: MakeETag

        public static string MakeETag(string UID, DateTime pLastModified)
        {
            byte[] hash = md5.ComputeHash(Encoding.ASCII.GetBytes(UID + "/" + pLastModified.ToBinary()));

            StringBuilder pendingETag = new StringBuilder();
            for (int i = 0; i < hash.Length; ++i)
                pendingETag.Append(hash[i].ToString("X2"));

            return "\"" + pendingETag.ToString() + "\"";
        }
開發者ID:danm36,項目名稱:Bismuth,代碼行數:10,代碼來源:HTTPResponse.cs

示例11: Write

 public static int Write(BinaryWriter writer, DateTime dateTime, int tick, string component, string thread, string message)
 {
     writer.Write(dateTime.ToBinary());
     writer.Write(tick);
     writer.Write(component);
     writer.Write(thread);
     writer.Write(message);
     writer.Flush();
     return (int)writer.BaseStream.Position;
 }
開發者ID:Fulborg,項目名稱:dwarrowdelf,代碼行數:10,代碼來源:MMLog.cs

示例12: Write

        public static int Write(BinaryWriter writer, DateTime dateTime, TraceEventType eventType, int tick,
			LogComponent component, string thread, string header, string message)
        {
            writer.Write(dateTime.ToBinary());
            writer.Write((int)eventType);
            writer.Write(tick);
            writer.Write((byte)component);
            writer.Write(thread);
            writer.Write(header);
            writer.Write(message);
            writer.Flush();
            return (int)writer.BaseStream.Position;
        }
開發者ID:tomba,項目名稱:dwarrowdelf,代碼行數:13,代碼來源:MMLog.cs

示例13: GetHistoricalPathRoots

        public DataAddress[] GetHistoricalPathRoots(IServiceAddress root, string pathName, DateTime time, int maxCount)
        {
            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machine = CheckMachineInNetwork(root);
            // Check it's root,
            if (!machine.IsRoot)
                throw new NetworkAdminException("Machine '" + root + "' is not a root");

            // Perform the command,
            RequestMessage request = new RequestMessage("getPathHistorical");
            request.Arguments.Add(pathName);
            request.Arguments.Add(time.ToBinary());
            request.Arguments.Add(time.ToBinary());

            ResponseMessage m = (ResponseMessage) Command(root, ServiceType.Root, request);
            if (m.HasError)
                throw new NetworkAdminException(m.ErrorMessage);

            // Return the data address array,
            return (DataAddress[])m.ReturnValue;
        }
開發者ID:yuexiaoyun,項目名稱:cloudb,代碼行數:23,代碼來源:NetworkProfile_Root.cs

示例14: Send

 public bool Send(int udpPort, string strType, string strSend, DateTime timeStamp)
 {
   if (socket == null)
     socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
   try
   {
     byte[] sendbuf = Encoding.UTF8.GetBytes(string.Format("{0}|{1}|{2}~", strType, strSend, timeStamp.ToBinary()));
     IPEndPoint endPoint = new IPEndPoint(hostIP, udpPort);
     socket.SendTo(sendbuf, endPoint);
     return true;
   }
   catch (SocketException se)
   {
     Log.Info("UDPHelper: Send port {0}: {1} - {2}", udpPort, se.ErrorCode, se.Message);
     return false;
   }
 }
開發者ID:arangas,項目名稱:MediaPortal-1,代碼行數:17,代碼來源:UdpHelper.cs

示例15: Log

 /// <summary>
 /// Write message to a file
 /// </summary>
 /// <param name="text"></param>
 /// <param name="InputStyle"></param>
 /// <param name="owner"></param>
 /// <param name="directory"></param>
 /// <param name="time"></param>
 public static void Log(string text, Client.ContentLine.MessageStyle InputStyle, Graphics.Window owner, string directory, DateTime time)
 {
     try
     {
         if (!Directory.Exists(Configuration.Logs.logs_dir))
         {
             Directory.CreateDirectory(Configuration.Logs.logs_dir);
         }
         if (!Directory.Exists(Configuration.Logs.logs_dir + Path.DirectorySeparatorChar + owner._Network.ServerName))
         {
             System.IO.Directory.CreateDirectory(Configuration.Logs.logs_dir + Path.DirectorySeparatorChar + owner._Network.ServerName);
         }
         if (!Directory.Exists(Configuration.Logs.logs_dir + Path.DirectorySeparatorChar + owner._Network.ServerName + Path.DirectorySeparatorChar + validpath(owner, directory)))
         {
             Directory.CreateDirectory(Configuration.Logs.logs_dir + Path.DirectorySeparatorChar + owner._Network.ServerName + Path.DirectorySeparatorChar + validpath(owner, directory));
         }
         if (Configuration.Logs.logs_txt)
         {
             string stamp = "";
             if (Configuration.Scrollback.chat_timestamp)
             {
                 stamp = Configuration.Scrollback.format_date.Replace("$1", time.ToString(Configuration.Scrollback.timestamp_mask));
             }
             Core.IO.InsertText(stamp + Protocol.DecodeText(Core.RemoveSpecial(text)) + "\n", _getFileName(owner, directory, time) + ".txt");
         }
         if (Configuration.Logs.logs_html)
         {
             string stamp = "";
             if (Configuration.Scrollback.chat_timestamp)
             {
                 stamp = Configuration.Scrollback.format_date.Replace("$1", time.ToString(Configuration.Scrollback.timestamp_mask));
             }
             Core.IO.InsertText("<font size=\"" + Configuration.CurrentSkin.FontSize.ToString() + "px\" face=" + Configuration.CurrentSkin.LocalFont + ">" + System.Web.HttpUtility.HtmlEncode(stamp + Protocol.DecodeText(Core.RemoveSpecial(text))) + "</font><br>\n", _getFileName(owner, directory, time) + ".html");
         }
         if (Configuration.Logs.logs_xml)
         {
             Core.IO.InsertText("<line time=\"" + time.ToBinary().ToString() + "\" style=\"" + InputStyle.ToString() + "\">" + System.Web.HttpUtility.HtmlEncode(Protocol.DecodeText(Core.RemoveSpecial(text))) + "</line>\n", _getFileName(owner, directory, time) + ".xml");
         }
     }
     catch (Exception fail)
     {
         Core.handleException(fail);
     }
 }
開發者ID:JGunning,項目名稱:OpenAIM,代碼行數:52,代碼來源:LineLogs.cs


注:本文中的System.DateTime.ToBinary方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。