2012-03-21 5 views

답변

1

을하려고 어떻게 든 런타임 중에 그것을 발견해야하거나 소스 코드를합니까? 두 번째 경우에는 this list을 사용할 수 있습니다.

+0

내 소스 코드가 필요합니다. 사용자가 시간대를 선택하면 내 앱이 그 표준 시간을 보여 주어야합니다. 내가 어떻게 할 수 있니? – abhishek

+0

이를 달성하려면 아마도 두 가지 방법이있을 수 있습니다. 소스 코드에서 시간대를 하드 코딩하는 것이 더 쉬운 방법 일 수 있지만 드물지만 시간대가 변경되면 사용중인 외부 리소스에 반영된다는 가정하에 유지 보수가 필요하지 않은 이점이 있습니다. 이것이 과도한 것처럼 보일지 모르지만, 이것이 매우 드물게 발생하는 사건을 어떻게보아야합니다. – teukkam

5

ICU Library은 휴대용이며 Qt 응용 프로그램에서 사용할 수 있습니다. (그것은 C/C++ API를 가지고 있습니다.) 많은 다른 기능 중에서 시스템에 알려진 시간대를 열거 할 수있는 TimeZone 클래스가 있습니다.

당신이 필요로하는 모든 간단한 목록입니다 경우가 과잉 될 수도 있지만 당신이이 시간대를 사용하고 다른 메타 데이터 (로케일 등)와 상호 작용하는 데 예상되는 경우,이 것 좋은 해결책.

+0

주어진 링크에서 라이브러리를 가져올 위치를 알지 못합니다. 직접 symbian 프로젝트에 이러한 라이브러리를 추가 할 수있는 방법이 있습니까? – abhishek

+0

다운로드 페이지 : http://site.icu-project.org/download. 이 페이지에는 Subversion 저장소의 주소뿐만 아니라 이진 및 소스 다운로드에 대한 링크가 포함되어 있습니다. Symbian 환경에 대한 경험이 없으므로 구체적인 내용을 제공 할 수는 없습니다. ICU 라이브러리는 일반적인 C/C++ 라이브러리입니다. 헤더를 포함하고 라이브러리 경로를 링커에 추가하십시오. Symbian 특정 도움말에 대한 새로운 질문을 만들 수 있습니다. –

1

here을 설명하는 qt5.2의 새로운 QTimeZone 클래스를 사용하는 또 다른 예제가 있습니다.

그들은 알려진 모든 시간대와 일광 절약 시간과 같은 특별한 설정을 나열하는 사용자 정의 위젯을 만듭니다.

기본 코드

가 게시 : 이것은 Qt를 기본 해결책이 아니다

#include <QDebug> 
#include <QByteArray> 
#include <QDateTime> 
#include <QList> 
#include <QTimeZone> 

#include "widget.h" 
#include "ui_widget.h" 

Widget::Widget(QWidget *parent) : 
    QWidget(parent), 
    ui(new Ui::Widget) 
{ 
    ui->setupUi(this); 

    // Fill in combo box. 
    QList<QByteArray> ids = QTimeZone::availableTimeZoneIds(); 
    foreach (QByteArray id, ids) { 
     ui->timeZoneComboBox->addItem(id); 
    } 

    // Connect combo box to slot to update fields. 
    connect(ui->timeZoneComboBox, SIGNAL(currentIndexChanged(int)), 
      SLOT(UpdateFields())); 

    // Update fields for initial value. 
    UpdateFields(); 
} 

void Widget::UpdateFields() { 

    QByteArray id = ui->timeZoneComboBox->currentText().toLatin1(); 
    QTimeZone zone = QTimeZone(id); 

    // Fill in fields for current time zone. 
    if (zone.isValid()) { 
     ui->descriptionLabel->setText(tr("<b>Description:</b> ") + id); 
     ui->countryLabel->setText(tr("<b>Country:</b> ") +  
      QLocale::countryToString(zone.country())); 
     ui->hasDaylightTimeCheckBox->setChecked(zone.hasDaylightTime()); 
     ui->isDaylightTimeCheckBox->setChecked(
      zone.isDaylightTime(QDateTime::currentDateTime())); 
     ui->hasTransitionsCheckBox->setChecked(zone.hasTransitions()); 
     QDateTime zoneTime = QDateTime(
      QDate::currentDate(), QTime::currentTime(), zone).toLocalTime(); 
     ui->dateEdit->setDate(zoneTime.date()); 
     ui->timeEdit->setTime(zoneTime.time()); 

     QTimeZone::OffsetData offset = zone.nextTransition(
      QDateTime::currentDateTime()); 
     if (offset.atUtc != QDateTime()) { 
      ui->nextTransitionLabel->setEnabled(true); 
      ui->nextTransitionLabel->setText(
      tr("<b>Next transition:</b> %1").arg(offset.atUtc.toString())); 
     } else { 
      ui->nextTransitionLabel->setEnabled(false); 
      ui->nextTransitionLabel->setText(
       tr("<b>Next transition:</b> none")); 
     } 
    } 
}