Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to do a countdown timer for 3 months

Posted on 2012-03-30
16
Medium Priority
?
592 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

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

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!

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

704 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