PDA

View Full Version : Date and hours



kjiu
12th November 2009, 21:15
Hj,

I have a question how to do:

in the notepad (xp) i click F5 and the date and hours appear..

Kjiu

scascio
12th November 2009, 21:40
Do you mean : How to respond to a keyPressEvent, get the current time, format it into a string, and fill a textedit?

kjiu
12th November 2009, 21:55
in the menu but the F5 (Shortcut)

like I press the F5 or a go to menu and selected, and the hour and date will be on textedit

squidge
12th November 2009, 22:16
So you want to know how to put the date and time into a text edit from a menu press/QAction? Or just date and hour?

kjiu
13th November 2009, 07:31
So you want to know how to put the date and time into a text edit from a menu press/QAction?

Yes, can you can me how to do it.

drizzt
13th November 2009, 08:04
hi

You get the current time/date by using: QDateTime::currentDateTime(). This class has a toString(format) method, too. Format is also a string, like ("dd.MM.YYYY/hh.mm.ss")
-> you get 13.11.2009/08.04.20
This string you can set in the textEdit field.

kjiu
13th November 2009, 13:59
like this ?


public void date()
{
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
java.util.Date date = new java.util.Date();
String datetime = dateFormat.format(date);
this.editor.insertPlainText(datetime);
}

kjiu
13th November 2009, 18:34
now I haven't errors but when I click on date it doesn't appear at editor


public void date()
{
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
java.util.Date date = new java.util.Date();
String datetime = dateFormat.format(date);
this.editor.insertPlainText(datetime);
}

squidge
13th November 2009, 19:16
Your using QtScript?

kjiu
13th November 2009, 19:27
no, I am using QT Jambi