B4J Question Set Date and Time from code

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
it's possible with B4j change The System Date and Time directly from code?
Thanks
 

micro

Well-Known Member
Licensed User
Longtime User
You don't need to redirect the outputs. You need to handle the ProcessCompleted event: https://www.b4x.com/android/forum/threads/jshell-library.34661/#content
Ok erel, you are right.

Strange, this is the code and the error:
B4X:
js.Initialize("js", "date", Array As String("-s", d))
Where d = Sun Jan 31 19:50:31 CET 2016
B4X:
Error: date: invalid date `"Sun Jan 31 19:50:31 CET 2016"'

Whit putty
B4X:
pi@raspberrypi ~ $ sudo date -s Sun Jan 31 19:50:31 CET 2016
date: extra operand `31'
Try `date --help' for more information.
pi@raspberrypi ~ $ sudo date -s "Sun Jan 31 19:50:31 CET 2016"
Sun Jan 31 19:50:31 CET 2016
pi@raspberrypi ~ $

With putty if the string Sun Jan 31 19:50:31 CET 2016 is inserted without double quote the date is not updated
while con double quote it's Ok.

What am I doing wrong with shell comand?o_O
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
After 22 posts we were able to find the real problem. That's good :)

This works:
B4X:
js.InitializeDoNotHandleQuotes("js", "date", Array As String("-s", "Mon Feb 01 08:32:31 CET 2016"))
Thanks Erel, very much.
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
only now I noticed a problem, if the current date on the raspberry is less than the date to be inserted work well, otherwise the raspberry crashes
On the Raspberry:
12:59:16
B4X:
Dim su As StringUtils
d = su.DecodeUrl(d, "UTF8")
Dim sh As Shell
sh.InitializeDoNotHandleQuotes("sh", "date", Array As String("-s", d))
sh.Run(-1)
Where d = Mon Dec 19 13:59:17 CET 2016
Now on raspberry is 13:59

If I want to go back one hour or less to the current time raspy crashes
If i send command with putty work fine
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
My guess is that the time change causes something else to crash. The code itself is correct.
I know that the code appears correct but there is another different and functional way?
.....and why only when less? o_O
The code now is incomplete for this problem.
Thanks
 
Last edited:
Upvote 0
Top