如何创建每天更改一次的唯一字符串ID [英] How to create a unique string id that changes once a day

查看:111
本文介绍了如何创建每天更改一次的唯一字符串ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个唯一的字符串,应该每天更改一次。如果我更改日期,那么它应该生成一个新字符串。



我尝试过:



Guid uid = Guid.NewGuid();

sessionID = Convert.ToBase64String(uid.ToByteArray());

sessionID = sessionID.Replace (=,);

sessionID = sessionID.Replace(+,);



我怎么能通过更改日期来改变这一点。

Hi, I am trying to create a unique string, that should change once a day. If i change the date then it should generate a new string.

What I have tried:

Guid uid = Guid.NewGuid();
sessionID = Convert.ToBase64String(uid.ToByteArray());
sessionID = sessionID.Replace("=", "");
sessionID = sessionID.Replace("+", "");

How can i change this with change of date.

推荐答案

每天执行此操作的唯一方法是在某处保留今日的GUID值,并在其中记录何时它最后一次更改 - 可能是一个数据库 - 然后当你想要获取GUID时,检查更改日期是否与今天匹配,如果没有,则获取新的日期。然后将新值存储到数据库或设置文件或文本中,或者......存储大量不同的方法来存储少量数据。
The only way to do it daily, is to keep a "today's GUID" value somewhere, and with it a record of when it was last changed - a database maybe - then when you want to fetch the GUID you check if the "changed" date matches today, and fetch a new one if it doesn't. You then store the new values to your DB or settings file, or text, or ... there are a huge number of different ways to store a small amount of data like this.


您的独特的字符串每天更改一次可能只是今天的日期。



每次你获取DateTime.Now的短日期版本时,你会得到当天唯一的字符串;而且,它告诉你的不仅仅是一个GUID(在这种情况下);即何时。
Your "unique" string "that changes once a day" could simply be today's date.

Every time you fetch the "short date version" of DateTime.Now, you get the unique string for that day; and, it tells you more than just a GUID (in this case); i.e. "when".


这篇关于如何创建每天更改一次的唯一字符串ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆