• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Alter Date with javascript

 
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I started to play around a bit with javascriptn trying to do some basic stuff.
For now I'm trying to get a by the user defined date, add 10 days and write it back to a textfield in the document.
For some reasson, I can't achieve what I'm trying to do, this is what I had so far.

JS:


HTML:
 
Saloon Keeper
Posts: 5915
152
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"date" is a not a Date object, and so it does not have a "getDate" method.

You can see error messages like this code causes in the browser console. For example in Firefox, you would turn on the developer tools: Tools -> Web Developer -> Toggle Tools
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I changed m function to:



And that kinda works, but gives me the milliseconds since epochtime.
When I try to format it, he starts nagging again that I can't use the date functions.

JS sucks.... That kind of bs you would never have in java
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lol something is still wrong. I tried to convert from epoch to a date with setUTCSeconds, this is the result:
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind... As I said two posts ago, it gave me the time in milliseconds, while I used seconds to convert, so using setUTCMilliseconds did the trick.

Thanks Tim for pointing me in the correct direction
 
Tim Moores
Saloon Keeper
Posts: 5915
152
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java would complain as well if you treat object as if they were of a different type.

You can't expect a Date object to be formatted just like you would wish it to when you assign it to a string variable (which is effectively what happens with the ".value = date"). The Date object has various methods you can use to get a date string formatted in whatever way you need it.

Edit: I see you solved it already - good to hear.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah but java would complain before I run my code or simply dont let me use the methods...
Not there yet. When testing it I noticed that it dosn't auto increment my month when a new one starts.
For example 28/09/2018 when added 10 days should return 08/10/2018, but it returns 08/09/2018.

To make it more clear here's my function again:

 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So apperently it does change the month automaticly, but for some reasson it always deducts a month too...
So I could solve it by simply adding a month, but still I would like to know why I need to, anyone care to explain?
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!