• Post Reply Bookmark Topic Watch Topic
  • New Topic

first day of the current month  RSS feed

 
sam davis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could someone please tellme the syntax to get the first day of the current month. or Any links that explains it would be really helpful..thanks .
 
Torsten Schippel
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sam,
try this:
Calendar c=Calendar.getInstance();
c.set(c.get(c.YEAR),c.get(c.MONTH),1);
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
System.out.println(sdf.format(c.getTime()));
Regards
Torsten
 
Malcolm Featonby
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you wanted the actual day change the SimpleDateFormat constructor call to this.
SimpleDateFormat sdf=new SimpleDateFormat("EEEEEEEE");
 
sam davis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all of your help...it worked..!!!
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just as an aside, you can also say:
c.set(c.DATE, 1);
instead of setting all of the month, day, and year.
 
sam davis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Thanks a lot for your help..working fine now..Appreciate it..
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!