Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to do a countdown timer for 3 months

Posted on 2012-03-30
16
Medium Priority
?
601 Views
Last Modified: 2012-05-08
please help i want a count down timer code for months.
count = 3
check current month = 03
decrement count by 1
and after three months ie month=06
count = 0.
0
Comment
Question by:Newton21205
  • 13
  • 3
16 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 37787978
please, elaborate what do you mean by that question ?
Do you have some code ?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37788005
perhpas something like thios:

java.util.Date d30 = new java.util.Date();
SimpleDateFormat sdf30  = new SimpleDateFormat("MM");
String month = sdf30.format(d30);
int intMonth = Integer.parseInt(month);

while(int j=0; j<3; j++) {
 intMonth++;

// do somthing with it 

}
 

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 37788008
If you want to do it in real time - better use windows scheduler and run sime task every month - write into file the month number
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Newton21205
ID: 37788015
i mean to say that the current month is March so on  June that is after three months the counter should be zero.
0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 37788063
String [] monthStrings = {"Jan","Feb",Mar","Apr","May","Jun","Jul","Aug","sep","Oct","Nov","Dec"};

java.util.Date d30 = new java.util.Date();
SimpleDateFormat sdf30  = new SimpleDateFormat("MM");
String month = sdf30.format(d30);
int intMonth = Integer.parseInt(month);

int count = intMonth;

while((count >0) {
 intMonth++;
count--;
System.out.println(monthsStrings[intMonth-1]);




}

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 37788083
This code I tested and it's working:

  String [] monthStrings = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","sep","Oct","Nov","Dec"};

java.util.Date d30 = new java.util.Date();
SimpleDateFormat sdf30  = new SimpleDateFormat("MM");
String month = sdf30.format(d30);
int intMonth = Integer.parseInt(month);

int count = intMonth;

    String monthName = "";    

while(count >0) {
 intMonth++;
count--;
 monthName =    monthStrings[intMonth-1];





}
        System.out.println(monthName);

Open in new window


Output:

Jun

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 37788110
This will do the same without having the array of months names:

java.util.Date d30 = new java.util.Date();
SimpleDateFormat sdf30  = new SimpleDateFormat("MM");
String month = sdf30.format(d30);
int intMonth = Integer.parseInt(month);

int count = intMonth;


while(count >0) {
 intMonth++;
count--;





}
        java.util.Date d301 = sdf30.parse(""+intMonth, new ParsePosition(0));


        SimpleDateFormat sdf301  = new SimpleDateFormat("MMM");

               System.out.println(sdf301.format(d301));

Open in new window


Output:

Jun

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 37788122
and if you use this format:

  SimpleDateFormat sdf301  = new SimpleDateFormat("MMMMMM");

it will print the full name of the month , insted of first three chars
0
 

Author Comment

by:Newton21205
ID: 37788124
for_yan: i want it for real time.
this is what im doin:
        Calendar notificationInterval = new GregorianCalendar();
        Date currentPaymentDate = subscription.getStartDate();
// set the timer here so after three months it will notify
        Date nextExpectedPaymentDate = currentPaymentDate + 3 months
0
 

Author Comment

by:Newton21205
ID: 37788132
currentPaymentDate  is in format dd/MM/yyyy
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37788138
If you want for real life - then you can use Java Quartz schedluer or TimerTask - however I would not recommend it
as you would need to maintain that java job for all the time to get you once a month notification
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37788147
I think yiu woull be better off if you use the Windows scheduler to schedule the program running notingfucayion at requirted date
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37788158
Jus write the program which will sedn notification, make a batch dfile out of it and go to winodws scheduler and schedule it to run say every three months or at any other schedule which you prefer
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37788175
To schedule in Winods is simple - go to Control panel - Task scheduler - click on add scheduled task , browsee to your batch file, then select Monthly schedule - and select those months you want your job to run

TYou'll not need to mainatin special java process running all the time on your machine to count months and you don't want additiional service, etc
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37788215
That is how you add months with calendar:
    Calendar cal = Calendar.getInstance();

        
        cal.add(Calendar.MONTH, 3);
        

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 37788233
           SimpleDateFormat sdf303 = new SimpleDateFormat("dd/MM/yyyy");

              

        Calendar cal = Calendar.getInstance();


        cal.add(Calendar.MONTH, 3);
        
           System.out.println(sdf303.format(cal.getTime()));

Open in new window


Output:

30/06/2012

Open in new window

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question