本文整理汇总了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);
}
示例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());
}
示例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();
}
示例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;
}
示例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);
}
示例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();
}
示例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");
}
示例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);
}
示例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);
}
示例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() + "\"";
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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);
}
}