2
$\begingroup$

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?

$\endgroup$
5
  • $\begingroup$ 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: stackoverflow.com/questions/14442049/… $\endgroup$ Commented Dec 13, 2021 at 19:26
  • $\begingroup$ This did not work in TextEditor or in the Python console... $\endgroup$
    – InamuraJIN
    Commented Dec 13, 2021 at 20:29
  • $\begingroup$ 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 $\endgroup$ Commented Dec 13, 2021 at 20:42
  • $\begingroup$ If you would like to install pytz, you can do so (using one of the methods in 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>) $\endgroup$ Commented Dec 13, 2021 at 20:51
  • $\begingroup$ 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.... $\endgroup$
    – Chris
    Commented Dec 14, 2021 at 17:17

1 Answer 1

4
$\begingroup$

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
$\endgroup$
5
  • $\begingroup$ Oh!!!! Thank you very much! How can I use this with Node's Value? $\endgroup$
    – InamuraJIN
    Commented Dec 13, 2021 at 19:51
  • $\begingroup$ 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? $\endgroup$
    – Lauloque
    Commented Dec 13, 2021 at 20:02
  • $\begingroup$ Hmm Sorry...I would be happy if I could enter it as an expression in the Value node, is that possible? i.imgur.com/92CMAF0.png I thought this method would work for both Shader and Geometry nodes $\endgroup$
    – InamuraJIN
    Commented Dec 13, 2021 at 20:22
  • $\begingroup$ 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? $\endgroup$
    – Lauloque
    Commented Dec 13, 2021 at 20:43
  • $\begingroup$ 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. $\endgroup$ Commented Dec 14, 2021 at 18:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .