Community Forums
Results 1 to 3 of 3

Thread: Set Java time interval variables

  1. #1
    Join Date
    Jan 2002
    Location
    Portsmouth, NH
    Posts
    102

    Set Java time interval variables

    This java class sets 4 $J()s
    $J(Date)
    $J(Time)
    $J(DateTime)
    $J(DayOfWeek)
    /*************************************************/

    import com.installshield.wizard.*;
    import java.util.*; //Used for Date and Calendar
    import java.text.*; //Used for DateFormat and TimeFormat

    public class GetTime extends WizardAction {
    private static Date now; //Date variable

    public void execute(WizardBeanEvent event) {
    Calendar today; //Calendar variable for day of the week
    String dateTimeString; //String variable for date and time
    String dateString; //String variable for date
    String timeString; //String variable for time
    String dayOfWeekString; //String variable for day of the week

    now = new Date(); //Set Date variable now to the current date and time
    dateTimeString = DateFormat.getDateTimeInstance().format(now); //Command to format both the date and time
    dateString = DateFormat.getDateInstance().format(now); //Command to format the date
    timeString = DateFormat.getTimeInstance().format(now); //Command to format the time

    today = new GregorianCalendar(); //Create a new Gregorian Calendar
    today.setTime(now); //Set the time to the present
    String weekDay[] = new DateFormatSymbols().getWeekdays(); //Capture the days of the week in an array
    dayOfWeekString = weekDay[today.get(Calendar.DAY_OF_WEEK)]; //Get the current day of the week

    try { /*Store the time and date into a JVM system property "DateTime" */
    System.setProperty("DateTime", dateTimeString);
    System.setProperty("Date", dateString);
    System.setProperty("Time", timeString);
    System.setProperty("DayOfWeek", dayOfWeekString);
    }
    catch (Exception e) { /* Print error message */
    System.out.println("Date or time unknown.");
    }
    }
    }
    Attached Files Attached Files

  2. #2
    Join Date
    Aug 2007
    Location
    Toronto, ON, Canada
    Posts
    8

    Using bean, time does not change

    I am using the function below but the time is not updating as I write the information to a log file.

    Here is how I am using it:
    Code:
    public void onBeginInstall(com.installshield.event.wizard.WizardContext arg0)
        {
            Calendar today;  //Calendar variable for day of the week
            String dateTimeString;  //String variable for date and time
            String dateString;  //String variable for date
            String timeString;  //String variable for time
            String dayOfWeekString;  //String variable for day of the week
    
            now = new Date();  //Set Date variable now to the current date and time
            dateTimeString = DateFormat.getDateTimeInstance().format(now);  //Command to format both the date and time
            dateString = DateFormat.getDateInstance().format(now);  //Command to format the date
            timeString = DateFormat.getTimeInstance().format(now);  //Command to format the time
    
            try 
            {   /*Store the time and date into a JVM system property "DateTime" */
                System.setProperty("DateTime", dateTimeString);
                System.setProperty("Date", dateString);
                System.setProperty("Time", timeString);
            } 
            catch (Exception e)
            {
                DisplayInformation("Caught IOException: ","Date or time unknown.");
            }
        }
    When I start the installation, I am running the function to set the time. Do I need to run this every time I need to proper time?

    Thanks for your help and providing a great function!
    Peter

  3. #3
    Join Date
    Jan 2002
    Location
    Portsmouth, NH
    Posts
    102

    Java log data is not updated/refreshed

    As I understand it, the log file you have created to monitor this function's accuracy is not being updated.

    Can you augment your code to create a second log file and see what values we get?

    Sounds like we get the right answers some time and the wrong answers at other times...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •