是否存在可以统一实施的时间检查器?例如,我想检查今天的日期和时间,是否可以从Google或其他来源打来电话以检查时间,这样我就不会检查用户设备的时间了。任何链接或信息都会有用。
答案 0 :(得分:1)
这是我使用的代码。它使用https和https://nist.time.gov/actualtime.cgi的时间使用UnityWebRequest(需要Unity 5.2.0或更高版本),使用协程等待响应
nist.time.gov/actualtime.cgi答复:
enter code here
body {
margin: 0;
padding: 0;
overflow-x: hidden;
overflow-y: hidden;
font-family: 'Cabin Condensed', sans-serif;
}
a {
text-decoration: none;
color: #B0BDC9;
}
#navbar {
padding: 1.25%;
background: #2F3236;
font-family: 'Fjalla One', sans-serif;
}
#navbar li {
display: inline;
padding: 15px;
}
.navbar-right {
float: right;
color: #B0BDC9;
}
.dropdown {
float: right;
overflow: hidden;
}
.dropdown-container {
display: none;
position: absolute;
top: 36px;
right: 4px;
text-align: center;
color: #B0BDC9;
background-color: #2F3236;
min-width: 110px;
z-index: 1;
}
.dropdown-container ul {
display: block;
left: auto;
right: 0;
margin-right: -10px;
width: 100px;
padding: 0px;
}
.dropdown-container ul li {
float: none;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
left: auto;
right: ;
}
.dropdown:hover .dropdown-container {
display: block;
}
.content {
margin: 0 auto;
margin-top: 75px;
width: 80%;
font-size: 1.2em;
color: #2F3236;
}
<link rel="stylesheet" type="text/css" href="personal_website.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<div id="navbar">
<li><a href="home.html">Home</a></li>
<li><a href="about_me.html">About Me</a></li>
<li><a href="interests.html">Interests</a></li>
<li><a href="publications.html">Publications</a></li>
<li><a href="contact.html">Contact</a></li>
<div class="navbar-right">
<li><a href="" target="_blank"><i class="fab fa-linkedin"></i></a></li>
<li><a href="" target="_blank"><i class="fab fa-twitter"></i></a></li>
<div class="dropdown">
<li><a href=""><i class="fas fa-language"></i></a></li>
<div class="dropdown-container">
<ul>
<li>English</li>
<li>Spanish</li>
</ul>
</div>
</div>
</div>
</div>
<div>
<h2 class="home-text">Text</h2>
</div>
代码:
// time * 10 == ticks
<timestamp time="1538381371720144" delay="0"/>
答案 1 :(得分:0)
据我所知,Unity不支持获取无法在本地设备上更改的时间的任何方式。我认为解决此问题的最佳解决方案是运行一个小的php脚本,以使用date()格式获取时间。
<?php echo "Today is " . date("Y/m/d");>
将返回本地时间
然后您可以使用WWW类
检索此数据。public static IEnumerator GetTimeStamp(string url, RequestCompletedCallback callback)
{
UnityWebRequest www = UnityWebRequest.Get(url);//url would be where the php script is hosted
www.SendWebRequest();
while (!www.isDone)
{
if (www.isNetworkError || www.isHttpError)
{
throw new System.ArgumentException("Web request failed: ", www.error);
}
yield return null;
}
// Store results in a string
if (callback != null)
{
string result = www.downloadHandler.text;
}
www.Dispose();
}
另一种解决方案是使用返回诸如timezonedb或timeanddate之类的日期的API