هل يوجد في الجافا built in function تنادي الtime
مثلا في الc++ يوجد get_hour أو get_second
هل يوجد شيء مشابه في الجافا ؟؟
أنا أريد بالتحديد second .
هل يوجد في الجافا built in function تنادي الtime
مثلا في الc++ يوجد get_hour أو get_second
هل يوجد شيء مشابه في الجافا ؟؟
أنا أريد بالتحديد second .
public void timEdatE(){
n.getTextArea().insert(new SimpleDateFormat("h:mm aa dd/MM/yyyy",Locale.getDefault()).format(new Date()),n.getTextArea().getCaretPosition());
}انا استخدم هذا الميثود في برنامج المفكره ...
تقدر تشوف النتيجه بنفس البرنامج لو كان عندك :)
import java.util.*;
import java.awt.*;
import java.applet.*;
/*
** a simple digital clock in Java (beta applet
** muquit@semcor.com
** December 05, 1995
*/
public class Dgclock extends Applet implements Runnable
{
Thread
timer=null;
Image[]
simage=new Image[10],
image=new Image[11];
Image
buf_image;
Graphics
gc;
int
width=15,
height=20;
public void init()
{
int
x,
y;
image[0]=getImage(getCodeBase(),"images/zero.gif");
image[1]=getImage(getCodeBase(),"images/one.gif");
image[2]=getImage(getCodeBase(),"images/two.gif");
image[3]=getImage(getCodeBase(),"images/three.gif");
image[4]=getImage(getCodeBase(),"images/four.gif");
image[5]=getImage(getCodeBase(),"images/five.gif");
image[6]=getImage(getCodeBase(),"images/six.gif");
image[7]=getImage(getCodeBase(),"images/seven.gif");
image[8]=getImage(getCodeBase(),"images/eight.gif");
image[9]=getImage(getCodeBase(),"images/nine.gif");
image[10]=getImage(getCodeBase(),"images/colon.gif");
simage[0]=getImage(getCodeBase(),"images/szero.gif");
simage[1]=getImage(getCodeBase(),"images/sone.gif");
simage[2]=getImage(getCodeBase(),"images/stwo.gif");
simage[3]=getImage(getCodeBase(),"images/sthree.gif");
simage[4]=getImage(getCodeBase(),"images/sfour.gif");
simage[5]=getImage(getCodeBase(),"images/sfive.gif");
simage[6]=getImage(getCodeBase(),"images/ssix.gif");
simage[7]=getImage(getCodeBase(),"images/sseven.gif");
simage[8]=getImage(getCodeBase(),"images/seight.gif");
simage[9]=getImage(getCodeBase(),"images/snine.gif");
try
{
buf_image=createImage(89,20);
gc=buf_image.getGraphics();
} catch (Exception e) gc=null;
}
public void start()
{
if (timer == null)
{
timer=new Thread(this, "Dgclock");
timer.start();
}
}
public void run()
{
while (timer != null)
{
repaint();
try
{
timer.sleep(1000);
}catch (InterruptedException e)
{
}
}
}
public void paintApplet(Graphics g)
{
int
i,
j,
k;
Date
now=new Date();
int
hour,
minute,
second;
String
hr,
min,
sec,
today;
hr=formatDate("%I",now);
min=formatDate("%M",now);
sec=formatDate("%S",now);
for (i=0; i <hr.length(); i++)
{
g.drawImage(image[hr.charAt(i)-'0'],i*width,0,this);
}
g.drawImage(image[10],i*width,0,this);
i++;
for (j=0; j < min.length(); j++)
{
g.drawImage(image[min.charAt(j)-'0'],i*width,0,this);
i++;
}
for (j=0; j < sec.length(); j++)
{
g.drawImage(simage[sec.charAt(j)-'0'],(i*width)+(j*7),0,this);
}
}
public void update(Graphics g)
{
if (buf_image != null)
{
paintApplet(gc);
g.drawImage(buf_image,0,0,this);
}
else
{
g.clearRect(0,0,89,20);
paintApplet(g);
}
}
// Left Pad a number
// taken from Clock2 by Per Reedtz Thomsen/Rachel Gollub
private String padElement(int expr, char padChar)
{
String result = "";
// I'm just padding 2 digit numbers
if (expr < 10) result = result.concat(String.valueOf(padChar));
result = result.concat(String.valueOf(expr));
return(result);
}
// Format a date according to the formatting string.
// taken from Clock2 by Per Reedtz Thomsen/Rachel Gollub
private String formatDate(String fmt, Date d)
{
String formattedDate = "";
// Retrieve the specific date information
int hour = d.getHours();
int minute = d.getMinutes();
int second = d.getSeconds();
int US_Hour = hour < 13 ? hour : hour - 12;
// Loop through the format string
for(int i = 0; i < fmt.length(); i++)
{
if (fmt.charAt(i) == '%') // We've hit a formatting command...
{
i++; // Move past the '%' sign
// Figure out the format.
switch (fmt.charAt(i))
{
case 'I': // Hour -- 01 to 12
formattedDate = formattedDate.concat(padElement(US_Hour, '0'));
//formattedDate=formattedDate.concat(String.valueOf(US_Hour));
break;
case 'M': // Minutes -- 00 to 59
formattedDate = formattedDate.concat(padElement(minute, '0'));
break;
case 'S': // Second -- 00 to 61 (leap seconds)
formattedDate = formattedDate.concat(padElement(second, '0'));
break;
default:
formattedDate = formattedDate.concat("??");
break;
}
}
else // A regular character
{
formattedDate = formattedDate.concat(String.valueOf(fmt.charAt(i)));
}
} // end for
return(formattedDate);
}
public void stop()
{
timer.stop();
timer=null;
}
}يا طالبة علم(f)(f)(f) الغالية ترى هذا مثال
لdigital clock
من احد المواقع (بس تراه قديم من زمان جدي;)...) ان شا الله يفيدك واكيد time
مأخوذ من system
شكرا على اهتمامكم
(f)رحيق(f) : من فين تجيبي هذه الأكواد أعطيني لينكات علشان أستفيد
وبالنسبة لtime قاعدة أحاول ،واذا واجهتني مشاكل قلتلكم
أنا في الحقيقة أحتاج الseconds للتالي:
لدي variable وأريد أن يتغير هذا الvariable في كل ثانية
مثلا في الثانية الاولى يكون 5 ثم في الثانية الثانية يكون 1 في الثانية الثالثة يكون 5 .....وهكذا
قيم الvariable تتأرجح بين 5 و 1 ولكن كيف أستطيع عمل ذلك ؟
لذلك فكرت في استخدام الثواني المعرّفة في النظام لتؤدي هذا الغرض .
والمشكلة الآن كيف أعرف أنّ الثواني تغيرت .
ما أريد برمجته باختصار:
اذا تغيرت قيمة الثواني غيّر قيمة الvariable
هل فهمتم قصدي ؟؟؟
خلاص استخدمي if else و راح تعرفين الباقي :)
ما ينفع أستخدم if else لأني أبغى قيم الvariable في تغير مستمر
يعني لازم أعمل loop بس لما أستخدمت while دخلت في endless loop لأن الثواني دائما تتغير وما في شرط يطلعني من الloop
ممكن تستخدمى هنا 2 threads
see the Class Date or Time
Methode
getSecond()
للأسف أن الكود التالي لايعمل بشكل جيد
Date d=new Date(); d.getseconds();
والمشكلة أنه عندما أكتب d. ثم تظهر ال function list تكون getsecond غير مفعّلة "hide"
مع العلم بأني ضمّنت كل ال library المتعلقة ب Date
ولكن هناك library لم أضمّنها وهي java.sql لأني ضمّنت بدل عنها java .util
لكن عندما أكتب d.get second يقبلها الcompiler ولا تظهر لي فيها أي أخطاء مع أنها غير مفعّلة في الأصل .
هل ضروري استخدام thread ؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟
أفيدوني في امري بارك الله فيكم .
أشعر أن الموضوع غير واضح لديكم هل تريدون تفاصيل أكثر ؟؟؟؟؟؟
;);)
[php]import java.io.*;
import java.util.*;
public class TimeTest
{
public static void main(String[] args)
{
Calendar _ErstellDatum; _ErstellDatum=Calendar.getInstance();
String jahr=""+(_ErstellDatum.get(Calendar.YEAR));
System.out.println(" Jahr :"+jahr);
String monaths=""+(_ErstellDatum.get(Calendar.MONTH)+1);
if (monaths.length()==1)monaths="0"+monaths;
System.out.println(" monaths :"+monaths);
String days=""+ (_ErstellDatum.get(Calendar.DAY_OF_MONTH));
if (days.length()==1)days="0"+days;
System.out.println(" days :"+days);
String hours=""+(_ErstellDatum.get(Calendar.HOUR_OF_DAY));
if (hours.length()==1)hours="0"+hours;
System.out.println(" hours :"+hours);
String minuten="" + (_ErstellDatum.get(Calendar.MINUTE));
if (minuten.length()==1)minuten="0"+minuten;
System.out.println(" minuten :"+minuten);
String seconden=""+(_ErstellDatum.get(Calendar.SECOND));
if (seconden.length()==1)seconden="0"+seconden;
System.out.println(" second :"+seconden);
}
}شكرا أخ khwlani
سأجرب هذه الطريقة وباذن الله تضبط .
وفق الله الجميع لما يحبه ويرضاه .
هذا الموضوع مغلق.