Help: What's wrong to get TimeMillis in this code?

Hi,
I want to get the TimeMillis from a Calender.
Everytime the date and time and correct, however,
the Date and TimeMillis are always wrong. Can
anybody tell me how to get the correct ones?
tz = TimeZone.getTimeZone("PST");
cal = Calendar.getInstance(tz);
cal.setTimeZone(tz);
// get date and time
nYear = cal.get(cal.YEAR);
nMonth = cal.get(cal.MONTH);
nDayofMonth = cal.get(cal.DAY_OF_MONTH);
nDayofWeek = cal.get(cal.DAY_OF_WEEK);
nHour = cal.get(cal.HOUR_OF_DAY);
nMin = cal.get(cal.MINUTE);
nSec = cal.get(cal.SECOND);
int miliSec = cal.get(cal.MILLISECOND);
// get TimeMillis
java.util.Date date = (java.util.Date)(cal.getTime());
long nTime = date.getTime();
Thanks very much,
Fan

Hi,
I'm having a similar problem.I have compare 2 dates and get the number of days between them.
Myplan is convert both dates to milisecs ,calculate, and re-convert to get days (how do i round it off only yo integers, no decimals).Any idea how i could do this?-
import java.util.Date;
import java.text.SimpleDateFormat;
class DateStamp{
public static void Main(String args[]){
doDate1;
String D;
int D1,D2,D3;
Date dt=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("dd-mm-yyyy");
/*When using method .setDate(x) ,is x an integer or String?can x=2/5/2002 or 2-5-2002?*/
public void doDate1{
dt.setDay(12);
dt.setMonth(12);
dt.setYear(102);
D=dt.getTime();
D.parseInt(D1);D=""
D=sdf.getTime();
D.parseInt(D2);
int D3=D2-D1;
int D3=D3/86400000;/*How do you convert milisec-to-days?*/
D=D3.toString().
System.out.println(D+"days have elapsed since then");
the compiler said this-
File Compiled...
--------------------------- Javac Output ---------------------------
DateStamp.java:7: Invalid expression statement.doDate1;^DateStamp.java:14: Instance variables can't be void: doDate1public void doDate1; ^2 errors
this problem is persistant, and i'm a java newbie ,Does anyone know what's wrong here?
Thanks!
Regards,
aesh83

Similar Messages

  • Updating iTunes 12.1 and get error message "The procedure entry point CMBlockBufferCopyDataBytes could not be located in the dynamic link library CoreMedia.dll - what went wrong and how to resolve this?

    Updating iTunes 12.1 and get error message "The procedure entry point CMBlockBufferCopyDataBytes could not be located in the dynamic link library CoreMedia.dll". What went wrong and how to resolve this?

    Entry point errors can often be fixed by deleting the offending dll, then repairing the component it is part of.
    For general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down the page in case one of them applies.
    Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
    If the advice above doesn't resolve things you could try this alternate version:
    iTunes 12.1.0.71 for Windows (64-bit - for older video cards) - itunes64setup.exe (2015-01-28)
    which is a 64-bit installer for the 32-bit version of the core application, similar to previous 64-bit releases.
    Or roll back to the previous build:
    iTunes 12.0.1.26 for Windows (32-bit) - iTunesSetup.exe (2014-10-16)
    iTunes 12.0.1.26 for Windows (64-bit) - iTunes64Setup.exe (2014-10-16)
    tt2

  • I cant reset my iphone because it demand restriction code, em stuck now, kindly help what to do to get the **** out ov this?

    I cant reset my iphone because it demand restriction code, em stuck now, kindly help what to do to get the **** out ov this?

    Force the phone into recovery mode, as described here, & restore it:
    http://support.apple.com/kb/ht1808

  • I accidently downloaded something that made my webcam flash on spuradically even once i deleted it. when i restarted my computer it got stuck at the white loading screen with the grey apple and wont go past there..what is wrong? will applecare cover this?

    i accidently downloaded something that made my webcam flash on spuradically even once i deleted it. when i restarted my computer it got stuck at the white loading screen with the grey apple and wont go past there..what is wrong? will applecare cover this?  my computer also slowed down drastically before it stopped working..thanks! HELP PLEASE!

    Take each of these steps that you haven't already tried. Stop when the problem is resolved.
    Step 1
    The first step in dealing with a boot failure is to secure your data. If you want to preserve the contents of the startup drive, and you don't already have at least one current backup, you must try to back up now, before you do anything else. It may or may not be possible. If you don't care about the data that has changed since your last backup, you can skip this step.   
    There are several ways to back up a Mac that is unable to boot. You need an external hard drive to hold the backup data.
         a. Boot into the Recovery partition, or from a local Time Machine backup volume (option key at startup.) When the OS X Utilities screen appears, launch Disk Utility and follow the instructions in this support article, under “Instructions for backing up to an external hard disk via Disk Utility.”
    b. If you have access to a working Mac, and both it and the non-working Mac have FireWire or Thunderbolt ports, boot the non-working Mac in target disk mode. Use the working Mac to copy the data to another drive. This technique won't work with USB, Ethernet, Wi-Fi, or Bluetooth.
    c. If the internal drive of the non-working Mac is user-replaceable, remove it and mount it in an external enclosure or drive dock. Use another Mac to copy the data.
    Step 2
    Press and hold the power button until the power shuts off. Disconnect all wired peripherals except those needed to boot, and remove all aftermarket expansion cards. Use a different keyboard and/or mouse, if those devices are wired. If you can boot now, one of the devices you disconnected, or a combination of them, is causing the problem. Finding out which one is a process of elimination.
    If you've booted from an external storage device, make sure that your internal boot volume is selected in the Startup Disk pane of System Preferences.
    Step 3
    Boot in safe mode. Note: If FileVault is enabled, or if a firmware password is set, or if the boot volume is a software RAID, you can’t do this. Post for further instructions.
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including wireless networking on certain Macs.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    When you boot in safe mode, it's normal to see a dark gray progress bar on a light gray background. If the progress bar gets stuck for more than a few minutes, or if the system shuts down automatically while the progress bar is displayed, your boot volume is corrupt and the drive is probably malfunctioning. In that case, go to Step 5.
    If you can boot and log in now, empty the Trash, and then open the Finder Info window on your boot volume ("Macintosh HD," unless you gave it a different name.) Check that you have at least 9 GB of available space, as shown in the window. If you don't, copy as many files as necessary to another volume (not another folder on the same volume) and delete the originals. Deletion isn't complete until you empty the Trash again. Do this until the available space is more than 9 GB. Then reboot as usual (i.e., not in safe mode.)
    If the boot process hangs again, the problem is likely caused by a third-party system modification that you installed. Post for further instructions.
    Step 4
    Sometimes a boot failure can be resolved by resetting the NVRAM.
    Step 5
    Launch Disk Utility in Recovery mode (see Step 1.) Select your startup volume, then run Repair Disk. If any problems are found, repeat until clear. If Disk Utility reports that the volume can't be repaired, the drive has malfunctioned and should be replaced. You might choose to tolerate one such malfunction in the life of the drive. In that case, erase the volume and restore from a backup. If the same thing ever happens again, replace the drive immediately.
    This is one of the rare situations in which you should also run Repair Permissions, ignoring the false warnings it may produce. Look for the line "Permissions repair complete" at the end of the output. Then reboot as usual.
    Step 6
    Reinstall the OS. If your Mac was upgraded from an older version of OS X, you’ll need the Apple ID and password you used to upgrade.
    Step 7
    Repeat Step 6, but this time erase the boot volume in Disk Utility before installing. The system should automatically reboot into the Setup Assistant. Follow the prompts to transfer your data from a Time Machine or other backup.
    Step 8
    This step applies only to older Macs (not current models) that have a logic-board ("PRAM") battery. Both desktop and portable Macs used to have such a battery. The logic-board battery is separate from the main battery of a portable. A dead logic-board battery can cause a gray screen at boot. Typically the boot failure will be preceded by loss of the startup disk and system clock settings. See the user manual for replacement instructions. You may have to take the machine to a service provider to have the battery replaced.
    Step 9
    If you get this far, you're probably dealing with a hardware fault. Make a "Genius" appointment at an Apple Store to have the machine tested. If you can't get to an Apple Store, go to another authorized service provider.

  • Recently loaded Lion on my laptop and now my computer crashes often. Black screen and keyboard lights up. Any ideas on what's wrong and how to fix this?

    Recently loaded Lion on my laptop and now my computer crashes often. Black screen and keyboard lights up. Any ideas on what's wrong and how to fix this?

    Everytime this happens Ihave to power down and restart! Any ideas would be appreciated!

  • Help, what's wrong with my upload function

    Hi,
    I want to write a java Bean (FileUploadBean) to upload the image files. I use a very simple txt file to test my Bean code, I've already know the syntax of the entity body of httpServletRequest object, it's like below:
    "-----------------------------7d327203032e
    Content-Disposition: form-data; name="toefl_form"; filename="C:\transfer\Picasso_ljm\jakarta-tomcat-4.0.1\webapps\junmin\image\test.txt"
    Content-Type: text/plain
    hi, this is a test;
    -----------------------------7d327203032e--
    My original test.txt file is only a line without '\r', '\n'.
    "hi, this is a test."
    But after call my upload function, the saved file is:
    hi, this is a test.
    There are 4 more bytes than the original file. Below is my FileUploadBean file, does anyone can figure out what's wrong in my upload function? Does the readLine read the return carriage and new line charactor too? Thank you very much!
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.ServletInputStream;
    import java.util.Dictionary;
    import java.util.Hashtable;
    import java.io.PrintWriter;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.FileOutputStream;
    import java.io.IOException;
    public class FileUploadBean {
    private String savePath, saveFilename, filepath, filename, contentType;
    // private Dictionary fields;
    public String getFilename() {
    return filename;
    public String getFilepath() {
    return filepath;
    public void setSavePath(String savePath) {
    this.savePath = savePath;
    public void setSaveFilename(String saveFilename) {
    this.saveFilename = saveFilename;
    public String getContentType() {
    return contentType;
    private void setFilename(String s) {
    if (s==null)
    return;
    int pos = s.indexOf("filename=\"");
    if (pos != -1) {
    filepath = s.substring(pos+10, s.length()-1);
    // Windows browsers include the full path on the client
    // But Linux/Unix and Mac browsers only send the filename
    // test if this is from a Windows browser
    pos = filepath.lastIndexOf("\\");
    if (pos != -1)
    filename = filepath.substring(pos + 1);
    else
    filename = filepath;
    private void setContentType(String s) {
    if (s==null)
    return;
    int pos = s.indexOf(": ");
    if (pos != -1)
    contentType = s.substring(pos+2, s.length());
    public void doUpload(HttpServletRequest request) throws IOException {
    ServletInputStream in = request.getInputStream();
    // read boundary
    byte[] line = new byte[256];
    int i = in.readLine(line, 0, 256);
    if (i < 3)
    return;
    int boundaryLength = i - 2;
    String boundary = new String(line, 0, boundaryLength); //-2 discards the newline character
    String newLine = new String(line, 0, i);
    if (newLine.startsWith("Content-Disposition: form-data; name=\""))
    if (newLine.indexOf("filename=\"") != -1) {
    setFilename(new String(line, 0, i-2));
    if (filename==null)
    return;
    //this is the file content
    i = in.readLine(line, 0, 256);
    setContentType(new String(line, 0, i-2));
    // blank line
    i = in.readLine(line, 0, 256);
    // read the first byte of the file
    i = in.read();
    FileOutputStream fo = new FileOutputStream((savePath==null? "" : savePath) + saveFilename);
    while (i != -1) {
    // if this byte is equal to the first byte of the boundary, then first mark this place, and
    // go ahead to check if it encounter the ending boundary. If it belongs to the file, then reset
    // the read position and reread.
    if( (char)i == '\r') {
    in.mark(256);
    i = in.read();
    char c1 = (char)i;
    i = in.read();
    char c2 = (char)i;
    i = in.readLine(line, 0, 256);
    // if it is the end of request body, then close the OutputStream. Since the first byte is
    // read already, then the final boundary size if +3
    if ( (c1 == '\n') && (c2 == '-') && (i==boundaryLength+3) // + 3 is eof
    && (new String(line, 0, i).startsWith(boundary.substring(1)))) {
    i = in.read();
    else {
    // it is not the eof, then write this byte into the outputStream and reset the read position
    fo.write(i);
    in.reset();
    i = in.read();
    } // end if
    // else if (char)i != '-', then write directly to the fileOutputStream
    else {
    fo.write(i);
    i= in.read();
    } // end while
    // close the fileOutputStream
    fo.close();
    }// end function

    HI,
    I find a bug myself. I add a line "i = in.read(line, 0, 256);" in doUpload function in the following position:
    String boundary = new String(line, 0, boundaryLength); //-2 discards the newline character
    i = in.read(line, 0, 256);
    String newLine = new String(line, 0, i);
    But still, when I was trying to read a image file, it even didn't finish reading and quit already! Still has bugs, need help!
    Junmin

  • What's wrong with getting something right first ti...

    I give up, twice I phoned BT prior to my move as it wouldn't let me complete the moving form online, twice someone said they'd call back and never did. By the time I spoke to sensible operator number 3 it became apparent that my move was going to be delayed and not be in anyway a smooth transition (yet again - memo to self, don't move). So having waited two weeks, taken a day off work, the engineer arrives to find the allocated line is no good for the property, but then why would it be as its the other side of the river and very close to the property we've just moved out of! So it's back to making more calls, losing the will to live and generally getting more and more disenchanted with the service. Is it really so hard to get things right without having all of this aggravation?

    If you would like to contact one of the UK based BT Care Team who moderate this forum, they should be able to help you.
    They can be contacted using this link BT Care Team
    They normally respond by phone or e-mail, within three working days, however you should get an immediate confirmation, with a tracking number.
    There are some useful help pages here, for BT Broadband customers only, on my personal website.
    BT Broadband customers - help with broadband, WiFi, networking, e-mail and phones.

  • IPod touch won't turn on charge or register on pc help what is wrong how do I fix?

    My iPod touch won't turn on or charge or register on the pc, what is wrong and how do. Fix it?

    Try:
    - iOS: Not responding or does not turn on
    - Also try DFU mode after try recovery mode
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    - If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
    - If still not successful that indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
    Apple Retail Store - Genius Bar

  • What is wrong with my converstion in this program fah to celsius

    package converter;
    import java.io.*;
    import java.text.*;
    public class Cel {
         public static void main(String arg[]) throws IOException {
            BufferedReader stdin =
            new BufferedReader ( new InputStreamReader (System.in));
            DecimalFormat twoDigitsPastPoint = new DecimalFormat("0.00");
            String get_value;
            double cel=0.00;
            char reply;
            System.out.print("ENTER CELSIUS: ");
            get_value= stdin.readLine();
            cel = Integer.parseInt(get_value);
            System.out.print("THE FAHRENHEIT DEGREE EQUIVALENT IS: "
            + twoDigitsPastPoint.format(fah_cel(cel)) + ".");
            System.out.print("\n");
                do {
                String get_value2, answer;
                double cel2=0.00;
                System.out.print("DO YOU WANT TO continue Y/N: ");
                answer = stdin.readLine();
                reply = answer.charAt(0);
                if (reply =='n' || reply=='N')
                    System.exit(0);
                else if (reply =='Y' || reply=='y')
                    System.out.print("ENTER CELSIUS: ");
                    get_value2= stdin.readLine();
                    cel2 = Integer.parseInt(get_value2);
                    System.out.print("THE FARHRENHEIT DEGREE EQUIVALENT IS: "
                    + twoDigitsPastPoint.format(fah_cel(cel2)) + ".");
                    System.out.print("\n");
            } while (reply== 'Y' || reply == 'y');
        public static double fah_cel(double c)
            double fah=0.00;
            fah = (9.0/5.0) * (c + 32);
            return(fah);
    }i do not get the correct conversion when i run the program . . . . . i also have another class in this program that i created before this class that converts from fah to celsius and it works

    yes thanks . . . . . i was googling around for different equations for this . . . . . the one my professor supplied with the homework was wrong . . . . .
    this is what i needed . . ((9.0/5.0) * celsius) + 32 . . . . it works now thanks.

  • HELP! I want to Get RID Of this THING :(

    Hi! Please HELP!
    I have Adobe Photoshop CC 14.1.2
    And i want to know how to get rid of this thing....
    When ever i move any layer it shows me this (Marked in RED)
    Its too annoying already know how much i am moving still shows me the static of movement in pixels :/ where would i find the option to get rid of it
    THANK YOU

    Photoshop > Preferences > Interface > Show Transformation Values?

  • HP G6 recovery help - what if I can't read the COA code

    My hard drive is in the process of crashing.  I"m grabbing my files quickly.  I'll likely pick up a SSD.  I"m doing research on how to rebuild/recover.
    I can't read the COA sticker on the bottom.  Is there any way to get the code off my computer while it is still running?  What are my options?

    Hi:
    Read this info, and use ABR to back up the OEM VLK key info and then you should be able to restore it on the new installation.
    http://dellwindowsreinstallationguide.com/a-clean-install-of-windows/microsoft-product-activation/th...

  • My server went down and now that it is back up my mail will not import back in help what steps do I do to rectify this?

    My server went down and now that it is back up it will not load my aol and gmail accounts mail help.  What steps do I do to make this happen?

    Hi there MeganElizabeth02061999,
    You may want to check your past purchases and see if you can find the tracks there. Take a look at the article below for more information.
    Downloading past purchases from the iTunes Store, App Store, and iBooks Store
    http://support.apple.com/kb/ht2519
    -Griff W.

  • What is wrong with the following Java servlet code that downloads files?

    Hi,
    I need urgent help.
    This is the issue. I have a JSP code that calls a Java servlet class. This class is used to download files from the JSP page. The following is the piece of code that does the file download.
    String pathOfFile = gsPath + "/" + gsFileName.substring(gsFileName.indexOf("~")+1);
    File F = new File(pathOfFile);
    res.setContentType("application/stream");
    res.setHeader("Content-Disposition", "attachment; filename=" +gsFileName.trim());
    This code works just fine with IE. However, when this is used with Netscape, the class name gets added to the original file name extension. For example, if the class name is 'FileRetriever' and the file being downloaded is originally named 'a.doc', the file gets a name of 'a.doc.FileRetriever' after download using Netscape or Mozilla.
    One way to solve this is by adding the appropriate file type in the MIME settings in browser preference. However, this not a permanent solution.
    Can somebody let me know the correct code to fix this issue?
    Thanks for your time.

    We loose control of the file name once we pass the original file name to the input stream. When our code instructs Netscape to write the file on the local disk using an output stream, that is when Netscape/Mozilla adds this additional extension to the original file. So, essentially, we do not know about this additional extension.
    Any ideas on how to resolve this?
    Thanks.

  • What is the best approach for executing this code only once?

    Hi,
    What would be the best way to this using JSF/Java web architecture? I have a login page, login.jsf, that submits login credentials to another servlet and if successful, is redirected to a login success page, which I have called "main.jsf", my application's main page. What I want to do, however, is when the login success mechanism redirects to my application, I want to run a bit of Java code (which requires access to the session object) that executes only once, and then redirects to my application's main page.
    In other words, I could put this Java code on my application's main page, but then it would execute every time a user visited it.
    Any advice on the most efficient way to do this?
    Thanks, - Dave

    laredotornado wrote:
    Thanks for your reply but I have a question. If the filter is executed on every page, then, assuming the user is logged in, the code would be executed every time. How can I create this such that my code snippet is executed only once, preferably after the user is re-directed to the login success page?It is more secure. On login just put the User object as attribute of HttpSession and check in the filter if it is there.

  • What is pack and upack doing in this code ?

    Hello ABAP Experts,
    wha is the purpose of unpack in this code below. ?
    LOOP AT datapak ASSIGNING <fs>.
        UNPACK <fs>-zcurr_type TO <fs>-zcurr_type.
        UNPACK <fs>-zp0_type   TO <fs>-zp0_type.
        UNPACK <fs>-zp1_type   TO <fs>-zp1_type.
        UNPACK <fs>-zp2_type   TO <fs>-zp2_type.
        UNPACK <fs>-zp3_type   TO <fs>-zp3_type.
        UNPACK <fs>-zp4_type   TO <fs>-zp4_type.
        UNPACK <fs>-zp5_type   TO <fs>-zp5_type.
        UNPACK <fs>-zp6_type   TO <fs>-zp6_type.
        UNPACK <fs>-zp7_type   TO <fs>-zp7_type.
        UNPACK <fs>-zp8_type   TO <fs>-zp8_type.
        UNPACK <fs>-zp9_type   TO <fs>-zp9_type.
        UNPACK <fs>-zp10_type   TO <fs>-zp10_type.
        UNPACK <fs>-zp11_type   TO <fs>-zp11_type.
        UNPACK <fs>-zp12_type   TO <fs>-zp12_type.
      ENDLOOP.
    Thanks,
    BWer

    F1 help for UNPACK.
    <i>
    UNPACK
    Basic form
    UNPACK f TO g.
    Effect
    Unpacks the packed field f and places it in thefield g with leading zeros. If g is too short, it istruncated on the left.
    Example
    DATA: P_FIELD(2) TYPE P VALUE 103,
          C_FIELD(4) TYPE C.
    UNPACK P_FIELD TO C_FIELD.
    P_FIELD: P'103C' --> C_FIELD: C'0103'
    Notes
    If f is not type P, it is converted to typeP (see MOVE).
    g should always be type C. Otherwise, unwanted sideeffects may occur.
    The sign in the packed number is ignored.
    The same runtime errors may occur as occur with thePACK statement.
    </i>
    Regards,
    Rich Heilman

Maybe you are looking for

  • Network carrier name not changing after using another sim

    Hi, My mobile was activated by the store representative later when I insert my Sim card the network carrier name shows the one used at the store. Moreover my phone is working normal with phone calls and SMS. How can I change the network name back to

  • Sys_context error

    Dear Friends, I created a function in database 10g to get OS name in Oracle Forms Version 6i. CREATE OR REPLACE FUNCTION fn1 RETURN CHAR IS tname VARCHAR2(200); BEGIN tname := UPPER(sys_context('USERENV','OS_USER')); RETURN tname; END; To get Os name

  • How to unlock my ipod?

    how to unlock my ipod? as it tells me to connect to itunes but when I do so up to the restore point the server becomes unavailable. pls help

  • Issue with Dictionary CBS Build - CE 7.1

    Hi, We have NWDI setup on 2004s SP13 where we have created a track for CE 7.1 Development. We are facing issue with Dictionary Project Activation.Can anyone let me know how do we fix this : [ddgen] [Info]    Initialize generation templates from confi

  • Udev custom rule needed for mounting an ipad via ifuse

    I followed the wiki for using ifuse to mount devices.  There is a rule made for iphone/ipads on that same page which I would like to adapt to an ipad2.  Can someone help me with creating a rule for this purpose?  I read the udev and writting udev rul