Hello my name is Nam , i come from Viet Nam , i am a newbie in maxscript
I create some scripts and want create a limitation , i seach internet and found a solution write by C#
https://stackoverflow.com/questions/6435099/how-to-get-datetime-from-the…
Can i use it in maxscript ? please help me , thank you very much
Forum topic · General Scripting
HOW TO GET TIME FROM THE INTERNET WITH MAXSCRIPT
By alexnguyen · 2017-07-04
Description
Comments (4)
:(
alexnguyen · 2017-07-05
thank but i can use it , maybe i can not use port 13 , can you help me ?
`
pixamoon · 2017-07-06
try this time from google:
try(
local response = ((dotnetClass "System.Net.WebRequest").Create "http://www.google.com").GetResponse()
local utcDateTimeString = response.Headers.get_Item "date"
response.dispose()
print utcDateTimeString
print (substring utcDateTimeString 6 20)
)catch()
Best,
Pixamoon
thank you very much
alexnguyen · 2017-07-07
i can do it :)
`
pixamoon · 2017-07-05
I found this by you:
http://forums.cgsociety.org/showthread.php?p=8320838
try this modified code
(
local client = dotnetObject "System.Net.Sockets.TcpClient" "time.nist.gov" 13
client.SendTimeout = 2000
local streamReader = dotnetObject "System.IO.StreamReader" (client.GetStream())
local response = streamReader.ReadToEnd asDotnetObject:true
local utcDateTimeString = response.Substring 7 17 asDotNetObject:true
local localDateTime = (dotnetClass "System.DateTime").ParseExact utcDateTimeString "yy-MM-dd HH:mm:ss" (dotnetClass "System.Globalization.CultureInfo").InvariantCulture (dotnetClass "System.Globalization.DateTimeStyles").AssumeUniversal
streamReader.Dispose()
print (localDateTime.ToString())
)
It looks like working here
But I'm not sure if it's a good solution, what if there is no internet ?