I'm having an issue with this little bit of conversion. I'm converting a string (_dateString) into a Calendar time. I am using DateFormat and SimpleDateFormat to accomplish this task. Everything seems to be working great, except for it figuring out whether it is AM or PM. According to SimpleDateFormat (Java Platform SE 7 ) I am using "aa" to get my AM or PM marker. How come in my output then, it believes it to be 4:45 am instead of 4:45 pm? Hour of Day should return the 24 hour clock, which should show 16 instead of 4. I have posted the output below my code.
Java Code:
import java.text.*;
import java.util.*;
public class Time{
static String _dateString = "08 Feb 2014, 4:45pm";
public static void main(String args[]){
Calendar cal=Calendar.getInstance();
[Code] ....
Output:
Java Code:
Today is Sat Feb 08 04:45:00 EST 2014
Year: 2014
Month: 1
Day of Month: 8
Day of Week: 7
Week Of Year: 6
Week of Month: 2
Hour: 4
Hour of Day: 4
Minute: 45
Second: 0
Millisecond: 0 mh_sh_highlight_all('java');
I would like to set a specific time for a Calendar instance. My below code will set a time one minute ahead of the current time, and format it to ISO8601 standard.
I now want to set another variable(deadlineDate), but to a specific time, say 5 minutes ahead. I would like to hardcode this in so I dont want it to change as a result of getting the instance of the Calendar(which sets it to the current time)
Essentially I am trying to regenerate the above code every minute and increment itself each cycle until it reaches the deadlineDate, which is a fixed datetime.
import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Scanner; public class Swipe_In { public String DTStart; //Swipe in Date Time
[code]....
I have got 2 questions on the above class...
1) I get an error "Cannot make a static reference to the non-static field DTStart" wherever i use DTStart in the main method....What's causing this error? and How do i fix it for good?
2) public String DTStart; Once i get the current date & time assigned to the above DTStart String in the main method i cannot use the updated value of DTStart in any other class. In another class i wanna create an instance(object) of this Swipe_In class with DTStart assigned to the current time(as in its main method)..I tried but the object's DTStart gets assigned to null.(( How do i achieve this?
In my java file I made Strings of date and time, but my MYSQL database needs Date and Time of course. I've tried to convert them, but I keep getting this exception: org.apache.jasper.JasperException: java.lang.NumberFormatException: For input string: "2013-02-20"
public class Vogel { static final String url = "jdbc:mysql://localhost:3306/turving"; public static void Insert(String datum, String tijd, String plaats, String spotternaam, String vogelsoort) { try { SimpleDateFormat format = new SimpleDateFormat("YYYY-MM-DD"); SimpleDateFormat formatt = new SimpleDateFormat("HH:MM:SS"); java.util.Date parsed = format.parse(datum); java.util.Date parsedd = formatt.parse(tijd); java.sql.Date sql = new java.sql.Date(parsed.getTime()); java.sql.Time sqll = new java.sql.Time(parsed.getTime());
I am trying to parse a XML string into `org.w3c.dom.Document` object.
I have looked at solutions provided [here](xml - How to convert String to DOM Document object in java? - Stack Overflow), [here](How to create a XML object from String in Java? - Stack Overflow) and a few other blogs that give a variation of the same solution. But the `Document` object's #Document variable is always null and nothing gets parsed.
Here is the XML
XMLMappingValidator v = new XMLMappingValidator("<?xml version="1.0" encoding="utf-8"?> " + "<mapping> " + "<container> " + "<source-container>c:stem.csv</source-container>
[Code] ....
When I call **v.getXML().toString()** I get `[#document: null]`
Clearly, the parse is failing. But I don't understand why.
I am trying to parse a XML string into `org.w3c.dom.Document` object.
I have looked at solutions provided [here](xml - How to convert String to DOM Document object in java? - Stack Overflow), [here](How to create a XML object from String in Java? - Stack Overflow) and a few other blogs that give a variation of the same solution. But the `Document` object's #Document variable is always null and nothing gets parsed.
Here is the XML
Java Code:
XMLMappingValidator v = new XMLMappingValidator("<?xml version="1.0" encoding="utf-8"?> " + "<mapping> " + "<container> " + "<source-container>c:stem.csv</source-container>
[Code] .....
When I call Java Code: **v.getXML().toString()** mh_sh_highlight_all('java');
I get Java Code: `[#document: null]` mh_sh_highlight_all('java');
Clearly, the parse is failing. But I don't understand why.
I have built a binary tree, from a file. In each node, I am storing each word as a string, and an int frequency for each time the word occurs. For the assignment, I need to find how many words occur only once in the file. I wrote the program, but for some reason I am getting a number different from what my professor is expecting.
As far as I know, this file has loaded into the tree correctly, because all of my other answers in the assignment are correct. What am I doing wrong?
public void findUnique() { System.out.println("There are " + findUniqueWords(root, 0) + " unique words."); } private int findUniqueWords(Node subTree, int uniqueCount) { // Base Case: At the end of the branch if(subTree == null){ return uniqueCount;
I am working on an assignment that I can't seem to figure out the final part to. The program takes in course data such as the time the class starts and how long it lasts. The time is in military time (0000 - 2400)
I need the output time to be the time the class started, plus the length of the class, and displayed in military time.
I can't for the life of me figure out how to do this. I have gotten a program that works for this time and minutes, and displays the correct 1020. But when I change the information to say
Start time: 0700 Length = 90 minutes
I get:
Endtime = 90
90 is technically correct, the way the formula is setup, but I need it to display 0900 not 90.
Here is the code that I have. Be easy, I'm still learning, and this is just the file I created to get the formula to work. Also, the verbose in here is just for my own debugging to make sure values should be what I'm expecting them to be.
public class calc { public static void main(String[] args) { double hours, minutes, length; double temp; int time = 2400; hours = time / 100; System.out.println("Hours are: " + hours);
I have an requirement of splitting a Date-Time String i.e. 2013/07/26 07:05:36 As you observe the above string has Date and Time with space in between them.
Now I want just want split the string not by delimiter but by length i.e. after 10th place and then assign it to 2 variable i.e. Date <----2013/07/26 and Time <---07:05:36 separately.
I have two classes. time_runner is used for testing my code.
This is what I'm using to test my code:
class time_runner { public static void main(String str[]) throws IOException { Time time1 = new Time(14, 56); System.out.println("time1: " + time1); System.out.println("convert time1 to standard time: " + time1.convert()); System.out.println("time1: " + time1); System.out.print("increment time1 five times: "); time1.increment();
[code]....
The two constructors are "Time()", which is the default constructor that sets the time to 1200, and "Time(int h, int m)" Which says If h is between 1 and 23 inclusive, set the hour to h. Otherwise, set the hour to 0. If m is between 0 and 59 inclusive, set the minutes to m. Otherwise, set the minutes to 0. Those are my two constructors that I pretty much have down. The three methods however I'm having trouble with. The "String toString()" Returns the time as a String of length 4. The "String convert()" Returns the time as a String converted from military time to standard time. The "void increment()" Advances the time by one minute.
public class Time { private int hour; private int minute; public Time(int h, int m) { if(h > 1 && h < 23) hour = h;
import java.util.Calendar; import java.util.GregorianCalendar; public class CalendarCalc { public CalendarCalc (){} private static void printCalendarMonthYear (int month, int year)
[Code] .....
IDE is telling me this:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method printCalendarMonthYear(int, int) is undefined for the type CalendarDisplay
at CalendarDisplay.main(CalendarDisplay.java:46)
Btw, I have a main class. This is just the class responsible for doing calculations.
i have a problem, i need build a calender in BlueJ. The program need to found if I put this one year have to give me the full schedule but only the first semester.
I am currently using notepad to create a Java program and using the command box to compile it and execute it and it has been working fine. I have the JDK version 7 so java.lang works which I know does not need to be imported. The Calendar method which should be recognized is not.
Here is the program. Cut this program and compile it in the command box. It will not recognize the Calendar method.
import java.util.*; class Practice4_2 { public static void main (String args[]) { Calendar cal = Calender.getInstance(); Date.now = new Date();
I created a calendar program so when the user enters a day number and a year it would show the calendar for the year . My issue was that I could not get the numbers to line up neatly and how they should look . Also if its not to much trouble I would like to know how to turn this in to a loop .
import java.util.Scanner; public class Calendar { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter a Year"); int Year = scanner.nextInt();
I'm working on a program that prompts the user to enter the year and first day of the year and displays the calendar table for that year on the console. For example, if the user entered the year 2005, and 6 for Saturday, Juanuary,1, 2005, the program should then display the calendar for each month of the year.
I have written the program and solved the problem for the most part. Only, I'm having terrific difficulty getting the output to properly format. I'm *almost* there. I'll post my program below and then output.
import java.util.Scanner; public class DisplayCalendar { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the year: "); int year = scanner.nextInt();
I am working on an application using JSP and SERVLET.
Somewhere I need to show the reminders on a particular date on calendar (Jsp page). I have used javascript for calendar and entering reminder from another UI. So I need to display an image on the calendar date which is matching with reminder date. The problem is how can I display the image on that date which is on calendar.
I am having trouble with getting output to be what I want. I can get the output when a user enters their values for month, day and time using a scanner object and they print correctly, but what I want is before they input values, to display the current date. Here is a snippet of what I am working with *these are in two separate files, the first has all the variables etc, the second has the main method.
In one java file:
Java Code:
private int numOfGuests, month, day, year; private GregorianCalendar eventDate = new GregorianCalendar(); public Event() { this("not assigned" , 0, new GregorianCalendar()); } public int getDay() {
[Code] ....
This gives me 0-0-0 as a result instead of current date.
I have a problem to display a popup with the information of the registered event. I would like the user to hover over a particular event exhibited only the description of the event without having to click on the event to view information. I would like to make an ajax request to that was displayed a popup.
But do not know how to implement jquery and javascript. Well, I am new to programming. My code that generates the schedule is as follows:
In my Bean have methods that make the selection of date and event. Have I configured the option of setEditable to true. Ajax function, jquery or javascript to show the popup containing only observation and event date. And looked at the documentation of primefaces and not found any implementation to solve my problem.
I am writing a short program to find the zodiac of a given birth date. I am checking to see if a calendar object falls between to other objects to see if the date falls within a certain zodiac sign. To accomplish this, I have the user enter a date, then that date is compared to dates taken from an array. The problem is sometimes the comparison doesnt seem to work work, giving the wrong zodiac. For example if I enter 03/28/1968, it finds Aries, as expected. However if I enter 03/20/1968, it returns Aries also, when it should return Pisces. Here is the sample code.
private static String determineSign(Date birthdate, String[][] zodiac) throws ParseException { // TODO Auto-generated method stub Date date = birthdate; for (int row = 0; row < zodiac.length; row++) { DateFormat date3 = new SimpleDateFormat("MM/dd"); Calendar compDate3 = Calendar.getInstance();
[Code] .....
This is the class that creates the table used for the zodiac dates -
public class ZodiacTable { static final int ROWS = 12; static final int COLUMNS = 3; //private ArrayList<String> zodiacNames; private String[][] zodiacNames;
[Code] ....
I cant seem to see why it returns the wrong zodiac..
I have a PrimeFaces page with a calendar component on it. Radio buttons on that page work fine and call the setter method on the back end. The Calendar however doesn't call the setter. The getter method is called on page display.I'm using the PrimeFaces v 5.0 jar file.
I need to add a few days to make an end date (for instance the start date is the first date selected, and then the end date is x amount of days after that... I think I should be using the add() method but I am not quite sure of where or how to do so)...
Java Code:
//Get an instance of Calendar and DateFormat class, and get current date from the system using OnClick method Calendar startVacation = Calendar.getInstance(); DateFormat fmtDate = DateFormat.getDateInstance(); DatePickerDialog.OnDateSetListener startVaca = new DatePickerDialog.OnDateSetListener() {