Solved

how to do a countdown timer for 3 months

Posted on 2012-03-30
16
580 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses

622 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