Fetstil Fetstil Kursiv Understrykning linje färgläggning tabellverk Punktlista Nummerlista Vänster Centrerat högerställt Utfyllt Länk Bild htmlmode
  • Forum & Blog
    • Forum - översikt
      • .Net
        • asp.net generellt
        • c#
        • vb.net
        • f#
        • silverlight
        • microsoft surface
        • visual studio .net
      • databaser
        • sql-server
        • databaser
        • access
        • mysql
      • mjukvara klient
        • datorer och komponenter
        • nätverk, lan/wan
        • operativsystem
        • programvaror
        • säkerhet, inställningar
        • windows server
        • allmänt
        • crystal reports
        • exchange/outlook
        • microsoft office
      • mjukvara server
        • active directory
        • biztalk
        • exchange
        • linux
        • sharepoint
        • webbservers
        • sql server
      • appar (win/mobil)
      • programspråk
        • c++
        • delphi
        • java
        • quick basic
        • visual basic
      • scripting
        • asp 3.0
        • flash actionscript
        • html css
        • javascript
        • php
        • regular expresssion
        • xml
      • spel och grafik
        • DirectX
        • Spel och grafik
      • ledning
        • Arkitektur
        • Systemutveckling
        • krav och test
        • projektledning
        • ledningsfrågor
      • vb-sektioner
        • activeX
        • windows api
        • elektronik
        • internet
        • komponenter
        • nätverk
        • operativsystem
      • övriga forum
        • arbete karriär
        • erbjuda uppdrag och tjänster
        • juridiska frågor
        • köp och sälj
        • matematik och fysik
        • intern information
        • skrivklåda
        • webb-operatörer
    • Posta inlägg i forumet
    • Chatta med andra
  • Konto
    • Medlemssida
    • Byta lösenord
    • Bli bonsumedlem
    • iMail
  • Material
    • Tips & tricks
    • Artiklar
    • Programarkiv
  • JOBB
  • Student
    • Studentlicenser
  • KONTAKT
    • Om pellesoft
    • Grundare
    • Kontakta oss
    • Annonsering
    • Partners
    • Felanmälan
  • Logga in

Hem / Forum översikt / inlägg

Posta nytt inlägg


Date-problem

Postades av 2002-05-23 20:17:09 - Åke Johansson, i forum java, Tråden har 2 Kommentarer och lästs av 895 personer

Hej! Jag har problem med datumhantering i en klass. I klassen hämtar jag dagens datum och dagens tid. Tiden räknar jag upp i en for-loop med en minut per varv. Koden ser ut som följer:

String dateOut;
DateFormat formaterare=DateFormat.getDateInstance(DateFormat.SHORT); //denna rad hör till den övre
Date idag=new Date();
dateOut=formaterare.format(idag);
String[]datum=new String[50];
for(int i=0;i<datum.length;i++)
{
datum[i]=dateOut;
}
int timma=idag.getHours();i
nt minuter=idag.getMinutes();
String [] tid=new String[50];
for(int i=0;i<tid.length;i++)
{
minuter=minuter + 1;
if(minuter>59)
{
timma=timma+1;
minuter=0;
}
tid[i]=timma+"."+minuter;
}

Problemet är att jag i samma klass har kontakt med en databas. Jag har därför importerat java.sql och java.util.
När jag så kompilerar klagar kompilatorn på att:"reference to Date is ambigious, both class java.sql.Date in java.sql and class java.util.Date in java.util match Date idag = new Date;".

Kan någon förklara vad jag skall göra åt detta?

Amatören


Svara

Sv: Date-problem

Postades av 2002-05-23 21:19:22 - Peter Ramström

Hello.

Jag antar att du borde kunna göra så här:

String dateOut;
DateFormat formaterare=DateFormat.getDateInstance(DateFormat.SHORT); //denna rad hör till den övre
java.util.Date idag=new java.util.Date();
dateOut=formaterare.format(idag);
String[]datum=new String[50];
for(int i=0;i<datum.length;i++)
{
datum[i]=dateOut;
}
int timma=idag.getHours();i
nt minuter=idag.getMinutes();
String [] tid=new String[50];
for(int i=0;i<tid.length;i++)
{
minuter=minuter + 1;
if(minuter>59)
{
timma=timma+1;
minuter=0;
}
tid[i]=timma+"."+minuter;
}

Alltså importera java.util.Date när du skapar Date objektet. istället för att importera Date-klassen i början av filen.

Jag vill minnas att classen List har samma dilemma... men jag är inte säker.

Vet inte om det finns en bättre/smartare lösning.
Men det bör funka :-Þ

Peter.



Svara

Sv: Date-problem

Postades av 2002-05-24 09:05:46 - Emma Magnusson

Har sagt det förr och säger det igen - använd inte klassen Date!
Använd klassen:
com.ms.wfc.app.Time


Den har funktioner för att lägga till och dra ifrån olika tidsenheter, förutom
det så kan man använda alla metoderna. Klassen Date verkar vara på
väg ut i periferin för där är över hälften av metoderna ej rekommenderade
att användas. (se nedan:)

/Emma

MSDN om com.ms.wfc.app.Time

Time Methods
Constructors Description
Time Creates a Time object.




Methods Description
add Creates a new Time object that represents the number of time units (100 nanoseconds) after the time that this Time object represents.

addDays Creates a new Time object that represents the number of days after the time that this Time object represents.

addHours Creates a new Time object that represents the number of hours after the time that this Time object represents.

addMillis Creates a new Time object that represents the number of milliseconds after the time that this Time object represents.

addMinutes Creates a new Time object that represents the number of minutes after the time that this Time object represents.

addMonths Creates a new Time object that represents the number of months after the time that this Time object represents.

addSeconds Creates a new Time object that represents the number of seconds after the time that this Time object represents.

addYears Creates a new Time object that represents the number of years after the time that this Time object represents.

compare Compares two Time objects.

compareTo Compares this Time object to another Time object.

equals Tests for equality.

formatLongDate Retrieves the Time object as a String using the long date format.

formatLongTime Retrieves the Time object as a String using the long time format.

formatShortDate Retrieves the Time object as a String using the short date format.

formatShortTime Retrieves the Time object as a String using the short time format.

fromFileTime Creates a Time object based on the specified value.

getDate Creates a Time object that represents the same date as this Time object but without a time of day specified.

getDay Retrieves the day of the month that this Time object represents.

getDayOfWeek Retrieves the day of the week that this Time object represents.

getDayOfYear Retrieves the day of the year that this Time object represents.

getHour Retrieves the hour of the day that this Time object represents.

getMillis Retrieves the milliseconds of the second that this Time object represents.

getMinute Retrieves the minutes of the hour that this Time object represents.

getMonth Retrieves the month of the year that this Time object represents.

getSecond Retrieves the seconds of the minute that this Time object represents.

getTimeOfDay Creates a Time object that represents the same time of day as this Time object, but without a date specified.

getYear Retrieves the year that this Time object represents.

save Stores the Time object in persisted storage.

setDate Creates a new Time object that contains the date from another Time object and the time of day from this Time object.

setTimeOfDay Creates a new Time object that contains the date from this Time object and the time of day from another Time object.

toDouble Retrieves the Time object as an OLE-formatted double value.

toFileTime Retrieves the Time object as a Win32 FILETIME value.

toLocalTime Creates a Time object that represents this Time object in the user's local time zone.

toLong Retrieves the number of time units (100 nanoseconds) units that are stored in this Time object.

toString Retrieves this Time object as a String object.

toSystemTime Retrieves this Time object as a Win32 SYSTEMTIME structure.

toUniversalTime Creates a new Time object that represents this Time object in the coordinated universal time (UTC) time zone.

toVariant Retrieves this Time object as a com.ms.com.Variant object.



Svara

Nyligen

  • 20:22 Spel
  • 17:07 Snabb och trevlig webbplats utan l
  • 17:00 Bra spelsajt med bonusar
  • 15:51 Slappna av
  • 15:17 Onlineunderhållning på fritiden
  • 11:13 Online Kasino
  • 17:57 Vart är SEO på väg till 2030?
  • 14:24 CBD regelbundet?

Sidor

  • Hem
  • Bli bonusmedlem
  • Läs artiklar
  • Chatta med andra
  • Sök och erbjud jobb
  • Kontakta oss
  • Studentlicenser
  • Skriv en artikel

Statistik

Antal besökare:
Antal medlemmar:
Antal inlägg:
Online:
På chatten:
4 569 662
27 955
271 721
5 609
0

Kontakta oss

Frågor runt konsultation, rådgivning, uppdrag, rekrytering, annonsering och övriga ärenden. Ring: 0730-88 22 24 | pelle@pellesoft.se

© 1986-2013 PelleSoft AB. Last Build 4.1.7169.18070 (2019-08-18 10:02:21) 4.0.30319.42000
  • Om
  • Kontakta
  • Regler
  • Cookies