I have a string i created with python to input to a Popup Calender.
When I try to link it to the date, I get the Error:
can't convert 'Thu Aug 21 16:56:40 EDT 2014' to java.util.Date
How do i convert a string into a java.util.Date?
Thanks all
I have a string i created with python to input to a Popup Calender.
When I try to link it to the date, I get the Error:
can't convert 'Thu Aug 21 16:56:40 EDT 2014' to java.util.Date
How do i convert a string into a java.util.Date?
Thanks all
Hi drewdin.
Can you post a sample of code giving your problem?
EDIT: The way that has always worked for me is to use java.text.SimpleDateFormat
[code]from java.text import SimpleDateFormat
inputFormat=SimpleDateFormat(âEEE MMM dd HH:mm:ss Z yyyyâ) # Must match the format of the input string
dt=âWed Mar 26 10:13:54 CET 2014â
event.source.parent.getComponent(âPopup Calendarâ).date=dateOut
inputFormat=SimpleDateFormat(âyyyy/MM/dd HH:mm:ssâ) # Must match the format of the input string
dt=â1967/09/24 15:25:45â
dateOut=SimpleDateFormat.parse(inputFormat,dt)
event.source.parent.getComponent(âPopup Calendarâ).date=dateOut[/code]
Thanks Jordan,
I ended up using:
[code]from java.text import SimpleDateFormat
fmt = '%a %b %d %H:%M:%S %Z %Y'
endtimestr = time.strftime(fmt)
inputFormat=SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy") # Must match the format of the input string
endtime=SimpleDateFormat.parse(inputFormat,endtimestr)[/code]
Where can i learn whats available for java in jython? Thanks again!
Everything in Java is available to Jython. It is one of the awesome things about Jython.
You could buy a book on Java or use Java resources on the Internet.
Was this issue sorted out. I have the same issueâŚ
canât convert â12/08/2018 09:34:40 AMâ to java.util.Date
Here is my code in event handlerâŚCode is executing till last line, because messagebox appears for newdate, but it is not executing the last line and error is canât convert to java.uitl.DateâŚ
Any solutions for thisâŚ
import time
import datetime
from java.util import Calendar
now = datetime.datetime.now()
dateSelector = event.source.parent.getComponent(âPopupCalendarEndâ)
if dateSelector.date > datetime.datetime.now():
system.gui.messageBox (str(now))
newdate=now.strftime("%m/%d/%Y %H:%M:%S %p")
system.gui.messageBox (newdate)
dateSelector.date=newdate
You are using pythonâs (jythonâs) datetime module. It doesnât yield a java.util.Date. Use the java datatypes as shown in Jordanâs post.
You can just system.date functions now.
As has been mentioned (thank you, gentlemen!), you are not using Java datatypes. That being said, Starting with v7.8.something, there are a whole slew of functions added under system.date.* that use java data types.
Your script can now be shortened to something like:
dateSelector = event.source.parent.getComponent('Popup Calendar')
now = system.date.now()
if system.date.isAfter(dateSelector.date , now):
dateSelector.date = now