Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I wnat to change lines as per the date change

i want code in jsp for auto expire date & change the line
Posted

1 solution

I'm not sure what you mean exactly, if you need to run a piece of code every day (as soon as the computers date changes) then I might have an answer for you :)

The example is in C# but java is very similar so I'm sure you'll be able to translate it.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleTest
{
    class Program
    {
        static System.Timers.Timer timer = new System.Timers.Timer(500);
        static DateTime LastDateExecuted = DateTime.Now;

        static void Main(string[] args)
        {
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
            timer.Start();

            Console.ReadLine();
        }

        static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (LastDateExecuted.Date != DateTime.Now.Date)
            {
                //
                // The date changed, do something
                DoSomeWork();

                //
                // Set the last date executed variable for this days checks
                LastDateExecuted = DateTime.Now.Date;
            }
        }

        private static void DoSomeWork()
        {
            Console.WriteLine("The date changed");
        }
    }
}


Hope this helps you :thumbsup:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900