2

I want to get the current time in Japan, not the keyframe time And it will set AM00:00 as 0 seconds AM00:01=60 AM00:10=600 AM00:30=1800 AM01:30=5400... I want to change all hours and minutes to seconds like this How can I display that in Node's Value?

InamuraJIN
  • 157
  • 9
  • If you're wiling to use some Python to drive a node's value(s), getting the current time in a target time zone seems to be easy to do: https://stackoverflow.com/questions/14442049/python-give-utc-time-get-time-in-japan-using-pytz – NeverConvex Dec 13 '21 at 19:26
  • This did not work in TextEditor or in the Python console... – InamuraJIN Dec 13 '21 at 20:29
  • Oh, apologies; I should have looked into the StackOverflow I linked a bit more. They don't show the full script -- it should be import datetime; import pytz; datetime.datetime.now(pytz.timezone('Asia/Tokyo')). But, pytz is not installed by default with Blender's copy of Python, so you would have to separately install it for this to work – NeverConvex Dec 13 '21 at 20:42
  • If you would like to install pytz, you can do so (using one of the methods in https://blender.stackexchange.com/a/240347/73773) by closing Blender, navigating to your Blender's installation folder, into the Python sub-folder, executing ./python.exe -m pip install pytz, and re-opening Blender. After doing this, the command should work in your Blender Python console, and return datetime.datetime(2021, 12, 14, 5, 49, 17, 84151, tzinfo=<DstTzInfo 'Asia/Tokyo' JST+9:00:00 STD>) – NeverConvex Dec 13 '21 at 20:51
  • can u please tell us what you want to do further with your "node value", which has then the time? which normally is a string...and until now you cannot do that much with a string in gn right now....i would understand it a bit more if you want to have e.g. the hours in an integer value.... – Chris Dec 14 '21 at 17:17

1 Answers1

4

This is not specific to Blender, but Python by itself can do that using the datetime module:

from datetime import datetime

now = datetime.now()

current_time = now.strftime("%H:%M:%S") print("Current Time =", current_time)

Result:

Current Time = 14:38:17
L0Lock
  • 15,965
  • 1
  • 20
  • 44
  • Oh!!!! Thank you very much! How can I use this with Node's Value? – InamuraJIN Dec 13 '21 at 19:51
  • I would need to know more about what you are trying to do with that. Do you intend to create a new node with the current time displayed, or you want to get the current time as a data to use in a node tree ? Would it be in shader, geometry or compositing node systems? – L0Lock Dec 13 '21 at 20:02
  • Hmm Sorry...I would be happy if I could enter it as an expression in the Value node, is that possible? https://i.imgur.com/92CMAF0.png I thought this method would work for both Shader and Geometry nodes – InamuraJIN Dec 13 '21 at 20:22
  • The ting is, the value node only supports only float numbers. A time stamp is a string. You would need to convert this into a float somehow, or use a float in the first place. For example instead of writing 14:38:17 you could output 1438,17. But what are you trying to achieve with this? Maybe there's a better solution that using a time stamp in the first place? – L0Lock Dec 13 '21 at 20:43
  • now returns an object that has fields for hours, minutes, and seconds, so the conversion would be easy. The real problem is that there's no way to insert that value into an Input Node in real time. – Marty Fouts Dec 14 '21 at 18:07