Timstamp

Status
Nicht offen für weitere Antworten.
N

Nessrine

Gast
Hallo allerseits,
Ich lese ein timestamp aus einer Datenbank, dann versuche ich es die zu konvertieren dafür habe

den Schönen programm hier im Forum gefunden:


Code:
    public static void main(String[] args) 
    throws Exception 
{  
   System.out.println(format1(1164372360)); 
    //System.out.println(format2(1012539600)); 
} 

static String format1(long timestamp) 
{ 
    long milli = (timestamp + sixHours) * 1000l; 
    return df1.format(new Date(milli)); 
} 

static String format2(long timestamp) 
{ 
    long milli = (timestamp + sixHours) * 1000l; 
    return df2.format(new Date(milli)); 
} 

static long sixHours = (60 * 60 * 1) ; 
static SimpleDateFormat df1 = new SimpleDateFormat("dd:MM:yyyy hh:mm a"); 
static SimpleDateFormat df2 = new SimpleDateFormat("hh:mm");

Mein Problem dass er mir für diesen Wert
17:11:2006 02:59 PM ausrechnet mit 6 Stunden verzögerung und ich will auf den Wert 2006-11-17 13:59:00 kommen
Ich habe lange gesucht könntet ihr mir bitte Tips geben

Danke im Voraus ; )
 

Verjigorm

Top Contributor
ähm verstehe ich das richtig, du willst anstatt die +6Stunden nun -1Stunde haben?

du hast ja schon aus sixHours
Code:
static long sixHours = (60 * 60 * 1) ;
eine Stunde gemacht
 
S

SlaterB

Gast
schöner Code, erinnert mich an meinen ;)

Code:
public class Test
{

    public static void main(String[] args)
        throws Exception
    {
        long time = 1164372360;
        System.out.println(format1(time));
        System.out.println(format6h(time));
    }

    static String format1(long timestamp)
    {
        long milli = timestamp * 1000l;
        return df1.format(new Date(milli));
    }

    static String format6h(long timestamp)
    {
        long milli = (timestamp + sixHours) * 1000l;
        return df1.format(new Date(milli));
    }

    static long sixHours = (60 * 60 * 6);
    static SimpleDateFormat df1 = new SimpleDateFormat("dd:MM:yyyy hh:mm a");

}
 
N

Nessrine

Gast
Hi

Danke für euere Antwort, ja ich bekomme es in PM das es was es mich durcheinander gebracht hat. Ja es gibt 1 Stund Differenz. Wie mache ich das?
Ach das es dein Code; ) Ich benutze es jetzt : )
 
N

Nessrine

Gast
Danke Danke es funktioniert

Jetzt muss ich es nur noch in C# Schreiben : )
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
G Timstamp mit Millisekunden Java Basics - Anfänger-Themen 2

Ähnliche Java Themen


Oben