当前位置: 首页>>代码示例>>C#>>正文


C# DateTime.ToUnixTime方法代码示例

本文整理汇总了C#中System.DateTime.ToUnixTime方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.ToUnixTime方法的具体用法?C# DateTime.ToUnixTime怎么用?C# DateTime.ToUnixTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.DateTime的用法示例。


在下文中一共展示了DateTime.ToUnixTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetChannelHistory

        public GroupsHistoryResponseModel GetChannelHistory(string slackApiToken, string channel, DateTime startTime, DateTime endTime, int count)
        {
            var responseString = "https://slack.com/api/channels.history"
                .PostUrlEncodedAsync(
                    new
                    {
                        token = slackApiToken,
                        channel,
                        latest = endTime.ToUnixTime(),
                        oldest = startTime.ToUnixTime(),
                        count
                    })
                .ReceiveString()
                .Result;

            var serializer = new JsonSerializer<GroupsHistoryResponseModel>();
            var response = serializer.DeserializeFromString(responseString);

            if (!response.ok)
            {
                throw new SlackApiException(response.error);
            }

            return response;
        }
开发者ID:prinzo,项目名称:Attack-Of-The-Fines-TA15,代码行数:25,代码来源:ChannelApi.cs

示例2: GetSecureUrl

        /// <summary>
        /// Gets a secure signed url for downloading through Amazon CloudFront
        /// </summary>
        /// <param name="resourceUrl">URL to the resource</param>
        /// <param name="expires">Expiry date for the download link</param>
        /// <param name="keyXml">Private key XML (Use OpenSSLKey to convert from pem format)</param>
        /// <param name="keypairId">Key Pair Id of the key from AWS Security Credentials page</param>
        /// <returns></returns>
        public static string GetSecureUrl(string resourceUrl, DateTime expires, string keyXml, string keypairId)
        {
            if (string.IsNullOrEmpty(resourceUrl))
            {
                throw new ArgumentNullException("resourceUrl");
            }

            if (string.IsNullOrEmpty(keyXml))
            {
                throw new ArgumentNullException("keyXml");
            }

            if (string.IsNullOrEmpty(keypairId))
            {
                throw new ArgumentNullException("keypairId");
            }

            if (expires < DateTime.Now)
            {
                throw new ArgumentException("Expiry date cannot be before current time.");
            }

            var unixExpiry = expires.ToUnixTime();
            var policy = BuildCannedPolicy(resourceUrl, unixExpiry);
            var rsa = GetRsaProvider(keyXml);
            var rsaSignature = rsa.SignData(Encoding.UTF8.GetBytes(policy), new SHA1CryptoServiceProvider());
            var signature = EncodeSignature(rsaSignature);

            return string.Format(
                            "{0}?Expires={1}&Signature={2}&Key-Pair-Id={3}",
                            resourceUrl,
                            unixExpiry,
                            signature,
                            keypairId);
        }
开发者ID:kbmkbackups,项目名称:AmazonSecureDownload,代码行数:43,代码来源:CloudFront.cs

示例3: GetAuthorizationCodes

        /// <summary>
        /// Gets all authorization codes that matches the specified redirect uri and expires after the
        /// specified date. Called when authenticating an authorization code.
        /// </summary>
        /// <param name="redirectUri">The redirect uri.</param>
        /// <param name="expires">The expire date.</param>
        /// <returns>The authorization codes.</returns>
        public async Task<IEnumerable<IAuthorizationCode>> GetAuthorizationCodes(string redirectUri, DateTime expires)
        {
            var db = this.GetDatabase();

            var min = expires.ToUnixTime();
            var codes = new List<IAuthorizationCode>();

            var keys = db.SortedSetRangeByScore(this.Configuration.AuthorizationCodePrefix, min, DateTimeMax);

            foreach (var key in keys)
            {
                var hashedId = key.ToString().Substring(this.Configuration.AuthorizationCodePrefix.Length + 1);
                var id = Encoding.UTF8.GetString(Convert.FromBase64String(hashedId));

                if (id.Contains(redirectUri))
                {
                    var hashEntries = await db.HashGetAllAsync(key.ToString());

                    if (hashEntries.Any())
                    {
                        var code = new RedisAuthorizationCode(hashEntries) { Id = hashedId };

                        codes.Add(code);
                    }
                }
            }

            return codes;
        }
开发者ID:ericklombardo,项目名称:Sentinel.OAuth,代码行数:36,代码来源:RedisTokenRepository.cs

示例4: GetCurrentChanged

        public UserExtended GetCurrentChanged(DateTime since)
        {
            var url = string.Format(ApiRoutes.User.CurrentSinceUrl, since.ToUnixTime());

            var obj = ToggleSrv.Get(url).GetData<UserExtended>();

            return obj;
        }
开发者ID:lbarbisan,项目名称:TogglAPI.Net,代码行数:8,代码来源:UserService.cs

示例5: ToUnixTimeTest

		public void ToUnixTimeTest()
		{

			DateTime dt = new DateTime(1970, 1, 1);
			var unixTime = dt.ToUnixTime();
			Assert.AreEqual(unixTime, (long)0);


		}
开发者ID:kodofish,项目名称:CalbucciLib.ExtensionsGalore,代码行数:9,代码来源:DateTimeExtensionsTests.cs

示例6: GetCurrentChanged

        public async System.Threading.Tasks.Task<UserExtended> GetCurrentChanged(DateTime since)
        {
            var url = string.Format(ApiRoutes.User.CurrentSinceUrl, since.ToUnixTime());

            var response = await ToggleSrv.Get(url);
            var obj = response.GetData<UserExtended>();

            return obj;
        }
开发者ID:lbarbisan,项目名称:TogglAPI.Net,代码行数:9,代码来源:UserServiceAsync.cs

示例7: ToUnixTime

        public void ToUnixTime()
        {
            /*
             "The Unix epoch is the time 00:00:00 UTC on 1 January 1970 (or 1970-01-01T00:00:00Z ISO 8601)."
             * See:
             * https://en.wikipedia.org/wiki/Unix_time#Encoding_time_as_a_number
             */
            var unixStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            long expected = 0;
            var actual = unixStart.ToUnixTime();
            Assert.AreEqual(expected, actual);

            // First second
            var test1 = new DateTime(1970, 1, 1, 0, 0, 1, DateTimeKind.Utc);
            expected = 1;
            actual = test1.ToUnixTime();
            Assert.AreEqual(expected, actual);

            // -1
            var test11 = new DateTime(1969, 12, 31, 23, 59, 59, DateTimeKind.Utc);
            expected = -1;
            actual = test11.ToUnixTime();
            Assert.AreEqual(expected, actual);

            /*
             * "At 01:46:40 UTC on 9 September 2001, the Unix billennium (Unix time number 1,000,000,000) was celebrated."
             */
            var test2 = new DateTime(2001, 9, 9, 1, 46, 40, DateTimeKind.Utc);
            expected = 1000000000;
            actual = test2.ToUnixTime();
            Assert.AreEqual(expected, actual);

            /*
             * "At 23:31:30 UTC on 13 February 2009, the decimal representation of Unix time reached 1,234,567,890 seconds (like the number row on a keyboard)."
             */
            var test3 = new DateTime(2009, 2, 13, 23, 31, 30, DateTimeKind.Utc);
            expected = 1234567890;
            actual = test3.ToUnixTime();
            Assert.AreEqual(expected, actual);

            /*
             * "At 06:28:15 UTC on Sun, 7 February 2106, the Unix time will reach 0xFFFFFFFF or 4,294,967,295 seconds which, for systems that hold the time on 32 bit unsigned numbers, is the maximum attainable"
             */
            var test4 = new DateTime(2106, 2, 7, 06, 28, 15, DateTimeKind.Utc);
            expected = 0xFFFFFFFF;
            actual = test4.ToUnixTime();
            Assert.AreEqual(expected, actual);

            /*
             * "At 16:53:20 UTC on 13 May 2014, the Unix time value 1,400,000,000 seconds was celebrated over the Web"
             */
            var test5 = new DateTime(2014, 5, 13, 16, 53, 20, DateTimeKind.Utc);
            expected = 1400000000;
            actual = test5.ToUnixTime();
            Assert.AreEqual(expected, actual);
        }
开发者ID:nikeee,项目名称:nth,代码行数:56,代码来源:DateTimeTests.cs

示例8: CreateSignature

        public string CreateSignature(long userId, long appId, string appSecret, DateTime now)
        {
            var bytes = BitConverter.GetBytes(userId)
                .Concat(BitConverter.GetBytes(appId))
                .Concat(BitConverter.GetBytes(now.ToUnixTime()))
                .Concat(Encoding.UTF8.GetBytes(appSecret))
                .ToArray();

            return _hashAlgorithm.ComputeHash(bytes).ToHexString().ToLower();
        }
开发者ID:niraltmark,项目名称:PicturesApp,代码行数:10,代码来源:IHashService.cs

示例9: Serialize_UTC_Date

        public void Serialize_UTC_Date()
        {
            var d = new DateTime(2001, 01, 01);

            d.ToJson().Print();
            "\"\\/Date(978325200000-0000)\\/\"".Print();
            d.ToUnixTime().ToString().Print();
            d.ToUnixTimeMs().ToString().Print();

            Assert.That(d.ToJson(), Is.EqualTo("\"\\/Date(978325200000-0000)\\/\""));
        }
开发者ID:permadiwibisono,项目名称:Test,代码行数:11,代码来源:JsonTests.cs

示例10: PlaintextMessage

		public PlaintextMessage(string path, int value, DateTime timestamp)
		{
			if (path == null)
			{
				throw new ArgumentNullException("path");
			}

			Path = path;
			Value = value;
			Timestamp = timestamp.ToUnixTime();
		}
开发者ID:haf,项目名称:Graphite.NET,代码行数:11,代码来源:PlaintextMessage.cs

示例11: ToUnixTime_ThenCorrectUnixTimeReturned

        public void ToUnixTime_ThenCorrectUnixTimeReturned()
        {
            // arrange
            const Int64 Expected = 1396137600;
            DateTime dateTime = new DateTime(2014, 03, 30, 0, 0, 0, 0);

            // act
            Int64 unixTime = dateTime.ToUnixTime();

            // assert
            unixTime.ShouldBeEquivalentTo(Expected);
        }
开发者ID:siml173,项目名称:ChenTelegramApi,代码行数:12,代码来源:DateTimeExtensionsTest.cs

示例12: GetScheduledLeagueGames

        public IEnumerable<ScheduledGame> GetScheduledLeagueGames(DateTime dateMin = default(DateTime), DateTime dateMax = default(DateTime))
        {
            var request = new RestRequest(RequestPaths.Dota2.League.ScheduledLeagueGames);

            var defaultDateTime = default(DateTime);
            if (dateMin != defaultDateTime)
                request.AddQueryParameter("date_min", dateMin.ToUnixTime());
            if (dateMax != defaultDateTime)
                request.AddQueryParameter("date_max", dateMax.ToUnixTime());

            var response = Execute<ScheduledLeagueGamesResponseWrapper>(request);
            return Mapper.Map<List<ScheduledGame>>(response.Games);
        }
开发者ID:kbrimble,项目名称:Dota2.Client,代码行数:13,代码来源:LeagueClient.cs

示例13: DateTimeToUnixTime_Works

        public void DateTimeToUnixTime_Works()
        {
            // UTC time
            var utcDateTime = new DateTime(2013, 9, 26, 22, 21, 11, DateTimeKind.Utc);
            Assert.That(utcDateTime.ToUnixTime(), Is.EqualTo(1380234071L));

            // Local time
            var localDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, TimeZoneInfo.Local);
            Assert.That(localDateTime.ToUnixTime(), Is.EqualTo(1380234071L));

            // Min value
            Assert.That(DateTime.MinValue.ToUnixTime(), Is.EqualTo(-62135596800L));
        }
开发者ID:ioliver85,项目名称:mixpanel-csharp,代码行数:13,代码来源:ExtensionsTests.cs

示例14: CreateFromCommentCount

 public static DynamicProfileBadge CreateFromCommentCount(string userName, int commentCount, DateTime newestCommentTime)
 {
     if (string.IsNullOrWhiteSpace(userName))
         throw new ArgumentNullException(nameof(userName));
     foreach (var ccn in CommentCountNames.OrderByDescending(kvp => kvp.Key))
     {
         if (commentCount > ccn.Key)
         {
             var template = BadgeTemplates[DynamicBadgeType.Comments];
             var description = string.Format(template.Description ?? string.Empty, ccn.Key);
             var link = $"{ClientConstants.UserUrlPrefix}/{userName}/comments/before/{newestCommentTime.ToUnixTime()}";
             return new DynamicProfileBadge(template.Image, description, link, newestCommentTime, template.Name, ccn.Value);
         }
     }
     return null;
 }
开发者ID:holzmaster,项目名称:OpenPr0gramm,代码行数:16,代码来源:ProfileBadge.cs

示例15: GetInRange

        public Event[] GetInRange(DateTime from, DateTime to, int[] hostids, TypeOfEvent typeOfEvent = TypeOfEvent.Trigger, TypeOfObjectRelatedEvent relatedEvent = TypeOfObjectRelatedEvent.Trigger)
        {
            if (from == null || to == null)
                throw new ArgumentNullException();

            var response = _event.Get(new Get
            {
                time_from = from.ToUnixTime(),
                time_till = to.ToUnixTime(),
                @object = relatedEvent,
                source = typeOfEvent,
                sortfield = new []{"eventid"},
                output = "extend",
                sortorder = new[] { "desc" }
            });
            return response;
        }
开发者ID:Bezarius,项目名称:ZabbixApi,代码行数:17,代码来源:EventAgent.cs


注:本文中的System.DateTime.ToUnixTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。