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


C# DateTimeOffset.ToUnixTimeSeconds方法代码示例

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


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

示例1: GetIdOfFirstPostOfDay

        public static int GetIdOfFirstPostOfDay(DateTimeOffset day)
        {
            var items = Query(
                $"/2.2/posts",
                $"pagesize=1&order=asc&min={day.ToUnixTimeSeconds()}&max={day.AddDays(1).ToUnixTimeSeconds()}&sort=creation").Result;

            return items[0].post_id;
        }
开发者ID:davidebbo,项目名称:ForumScorer,代码行数:8,代码来源:QueryHelpers.cs

示例2: ToUnixTimeInSeconds_DateTimeOffset_ShouldMatch

        public void ToUnixTimeInSeconds_DateTimeOffset_ShouldMatch()
        {
            var offset = new DateTimeOffset(2016, 1, 8, 4, 11, 28, TimeSpan.FromHours(7));
            var expected = offset.ToUnixTimeSeconds();
            var actual = offset.ToUnixTimeInSeconds();

            Assert.AreEqual(expected, actual);
        }
开发者ID:Syn-McJ,项目名称:PlugToolkit,代码行数:8,代码来源:UnixDateTimeHelperTests.cs

示例3: EncodeBlockHeader

        public static byte[] EncodeBlockHeader(UInt32 Version, UInt256 PreviousBlock, UInt256 MerkleRoot, DateTimeOffset Time, UInt32 Bits, UInt32 Nonce)
        {
            using (var stream = new MemoryStream())
            using (var writer = new BinaryWriter(stream))
            {
                writer.WriteUInt32(Version);
                writer.WriteUInt256(PreviousBlock);
                writer.WriteUInt256(MerkleRoot);
                writer.WriteUInt32((uint)Time.ToUnixTimeSeconds());
                writer.WriteUInt32(Bits);
                writer.WriteUInt32(Nonce);

                return stream.ToArray();
            }
        }
开发者ID:cole2295,项目名称:BitSharp,代码行数:15,代码来源:DataEncoder.cs

示例4: UnixTime

        // to unitime
        /*
        public static int UnixTime(DateTime now)
        {
            //(long)new DateTime(1970, 1, 1, 9, 0, 0, 0).ToFileTimeUtc();
            return (int)(now.ToFileTimeUtc() / 10000000 - 11644506000L);
        }
        */
        private void Form1_Load(object sender, EventArgs e)
        {
            string dt_str = "";

            // unixtime : date
            this.label2.Text = "^:UnixTime  v:DateTime";

            DateTime now_unix_time_dt = DateTime.Now;
            TimeSpan ts = new TimeSpan(0, 0, 0, 0);
            now_unix_time_dt = now_unix_time_dt + ts;

            dt_str = now_unix_time_dt.ToString();
            this.textBox2.Text = dt_str;

            var dto = new DateTimeOffset(now_unix_time_dt, new TimeSpan(+09, 00, 00));
            var dtot = dto.ToUnixTimeSeconds();

            dt_str = dtot.ToString();
            this.textBox1.Text = dt_str;
        }
开发者ID:subteon,项目名称:UTConverter,代码行数:28,代码来源:Form1.cs

示例5: OnClipBoardChanged

        // クリップボードにテキストがコピーされると呼び出される
        private void OnClipBoardChanged(object sender, ClipboardEventArgs args)
        {
            string input_str;
            int i = 0;

            this.textBox1.Text = args.Text;
            input_str = this.textBox1.Text;

            // unixtime or datetime を確認
            DateTime dt;
            if (DateTime.TryParse(input_str, out dt))
            {
                // date -> unixtime
                this.label2.Text = "DateTime -> UnixTime";

                var dto = new DateTimeOffset(dt, new TimeSpan(+09, 00, 00));
                var dtot = dto.ToUnixTimeSeconds();

                string dt_str = dtot.ToString();
                this.textBox2.Text = dt_str;

            }
            else if ( int.TryParse(input_str, out i) )
            {
                // unixtime -> date
                this.label2.Text = "UnixTime -> DateTime";

                //int input_int = int.Parse(input_str);

                var dto = (DateTimeOffset.FromUnixTimeSeconds(int.Parse(input_str)).ToLocalTime());

                string dt_str = dto.ToString();
                this.textBox2.Text = dt_str;

            }
            else
            {
                this.label2.Text = "DateTimeに変換できません。";
                this.textBox2.Text = "";
            }
        }
开发者ID:subteon,项目名称:UTConverter,代码行数:42,代码来源:Form1.cs

示例6: GetStackOverflowReputation

        async Task<int> GetStackOverflowReputation(DateTimeOffset start, DateTimeOffset end, int firstPostIdToConsider)
        {
            dynamic items = await QueryHelpers.Query(
                $"/2.2/users/{StackOverflowID}/reputation",
                $"fromdate={start.ToUnixTimeSeconds()}&todate={end.ToUnixTimeSeconds()}");

            int reputation = 0;
            foreach (var item in items)
            {
                // Ignore if the post that the event is attached to is too old
                if (item.post_id < firstPostIdToConsider)
                    continue;

                if (item.vote_type == "up_votes")
                {
                    if (item.post_type == "answer")
                    {
                        reputation += 10;
                    }
                    else
                    {
                        // No points for upvotes on questions
                    }
                }
                else if (item.vote_type == "accepts")
                {
                    reputation += 20;
                }
                else
                {
                    // We ignore bounties
                }
            }

            return reputation;
        }
开发者ID:davidebbo,项目名称:ForumScorer,代码行数:36,代码来源:User.cs


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