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?
1 Answer
$\begingroup$
$\endgroup$
5
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
-
$\begingroup$ Oh!!!! Thank you very much! How can I use this with Node's Value? $\endgroup$ 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$ 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 output1438,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
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$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 returndatetime.datetime(2021, 12, 14, 5, 49, 17, 84151, tzinfo=<DstTzInfo 'Asia/Tokyo' JST+9:00:00 STD>)
$\endgroup$