HOW TO GET TIME FROM THE INTERNET WITH MAXSCRIPT

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

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexnguyen's picture

:(

thank but i can use it , maybe i can not use port 13 , can you help me ?

pixamoon's picture

`

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

alexnguyen's picture

thank you very much

i can do it :)

pixamoon's picture

`

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 ?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.