SORU
17 EYLÜL 2008, ÇARŞAMBA


Nasıl kullanıcı tarih/saat ekran'yerel biçim ve zaman mahsup s?

Sunucu her zaman html UTC tarihler hizmet ve istemci sitesinde javascript, kullanıcının yerel saat dilimi dönüştürmek istiyorum.

Eğer yapabilirsem Bonus kullanıcının yerel tarih biçimi çıktı.

CEVAP
17 EYLÜL 2008, ÇARŞAMBA


UTC tarihi ile başlamak için en kusursuz görünüyor Date yeni bir nesne oluşturmak ve setUTC… yöntemlerden istediğiniz zaman/tarih ayarlamak için kullanmaktır.

toLocale…String çeşitli yöntemleri lokalize çıkışı sağlayacaktır.

Örnek:

// This would come from the server.
// Also, this whole block could probably be made into an mktime function.
// All very bare here for quick grasping.
d = new Date();
d.setUTCFullYear(2004);
d.setUTCMonth(1);
d.setUTCDate(29);
d.setUTCHours(2);
d.setUTCMinutes(45);
d.setUTCSeconds(26);

alert(d);                        // -> Sat Feb 28 2004 23:45:26 GMT-0300 (BRT)
alert(d.toLocaleString());       // -> Sat Feb 28 23:45:26 2004
alert(d.toLocaleDateString());   // -> 02/28/2004
alert(d.toLocaleTimeString());   // -> 23:45:26

Bazı referanslar:

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Jay Will

    Jay Will

    19 NİSAN 2006
  • Julian Smith

    Julian Smith

    31 EKİM 2006
  • UniqueApps

    UniqueApps

    4 Ocak 2009