简体   繁体   English

在C#中将数字添加到数字日期值的末尾

[英]Add number to the ending of a numerical date value in C#

I'm trying to store an ID with the Date (month/day/year) in the same integer value in C#. 我正在尝试将ID(带有日期(月/日/年))存储在C#中相同的整数值中。

This way I can check whether a specific Id was already voted on in a particular day and prevent double voting in the same day. 这样,我可以检查特定ID是否已在特定日期进行投票,并防止同一天进行两次投票。 I store the votes in a static variable. 我将选票存储在静态变量中。

I convert the date to long using this code: 我使用以下代码将日期转换为long:

long.Parse(DateTime.Now.ToString("yyyyMMdd"));

So for today (2/9/2015) I get: 20150209 所以对于今天( 20150209 )我得到: 20150209

Now my IDs are integers. 现在我的ID是整数。 I want to append those to the converted date number. 我想将它们附加到转换后的日期数字上。

So if for example the ID is 138, I want to add 138 to the end of the number, so the end result would be: 20150209138 . 因此,例如,如果ID是138,我想在数字的末尾添加138,则最终结果将是: 20150209138

How can I append the id to the converted numerical date like I've explained above? 像上面已经解释过的,如何将id附加到转换后的数字日期上?

long.Parse(DateTime.Now.ToString("yyyyMMdd")+ID.ToString());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM