Solved

how to do a countdown timer for 3 months

Posted on 2012-03-30
16
548 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
advertisement module in core php 4 159
thymeleaf natural templating vs JSP 2 95
Java Jpanels and Jframe 8 33
MySqlDump not dumping triggers 1 30
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

776 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