• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to retrieve day in MIDlet?

 
Mirai Chelean
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, i'm new in J2ME and need help on how to retrieve the date. Does J2Me provide function like Date() in php? For example in php, date("l") means day of the week. I have the coding below which showing the date in full format, but can anybody tell me how to retrieve them by seperate?

example code:

Date today;
DateField datefield;

today=new Date(System.currentTimeMills());
datefield=new DateField("",DateField.DATE_TIME);
datefield.setDate(today);
.
.
.

Thanks and regards,
Mirai
 
Ramender Mall
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mirai,

I went throught the MIDP2.0 specifications....and really there was no such method to extract the fields of the dates separately....

I believe we have to find a work around for this..

My suggestion is , use toString() and subString() to get the separate fields, like here in the below given date..

date: Thu Oct 27 18:04:37 UTC 2005


you may abstract the "Thu" by converting date to String and then using substring with the index 3....and then use it for further processing specific to your need....

try it...
Ramy...
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually it is much simpler.

Just change your code

datefield=new DateField("",DateField.DATE_TIME);

to

datefield=new DateField("",DateField.DATE);

The constant you used in DateField makes it show the date and time.

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This reply is just a test, the Saloon seems slow to me and I want to see what it is waiting on.

Mark
 
Ramender Mall
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,


Just change your code

datefield=new DateField("",DateField.DATE_TIME);

to

datefield=new DateField("",DateField.DATE);

The constant you used in DateField makes it show the date and time.

But even if change it to Date field, the value we will get back will be in comlete date....like -->WED NOV 12/12/2005 and something...
So to get each n every field(like day or month)....is there any other way?....

Thanx...
n a very gud day....
 
Niklas Junel
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you try an object from Calendar instead?

Calendar cal = Calendar.getInstance();
int tmp = cal.get(Calendar.DAY_OF_WEEK);

if(tmp == Calendar.SUNDAY){
//put your code here, if you are working with sunday
}
 
Ramender Mall
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nikles,

This, is what, Mirai was looking for......

Thanx for the information......
 
Mirai Chelean
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all guys, thank you!
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic