An warware: saita yankin lokaci a cikin tashar debian

Saita yankin lokacin tsarin ku na iya zama aiki mai mahimmanci yayin kiyaye sabar ko haษ“aka aikace-aikacen da ke buฦ™atar yin la'akari da yankin masu amfani. A cikin tsarin Linux, kamar Debian, akwai ingantacciyar hanya don yin wannan ta amfani da yaren shirye-shiryen C a cikin tashar. Wannan hanya madaidaiciya ce kuma tana iya zama mai ฦ™arfi sosai, tana ฦ™yale tsarin ku yayi aiki daidai da haษ—in kai.

Saita Yankin Lokaci a cikin Debian Terminal: Magani

Hanya mafi kyau don saita yankin lokaci a cikin tashar Debian shine amfani da aikin 'tzset' daga ษ—akin karatu na'time.h' a cikin C. Wannan aikin yana karanta ma'aunin yanayin 'TZ' don tantance yankin lokaci na yanzu. Don canza yankin lokaci, muna buฦ™atar canza wannan 'TZ' mai canzawa daidai da haka.

Anan ga shirin C mai sauฦ™i tare da lambar da ake buฦ™ata don cika wannan:

#include <time.h>
#include <stdlib.h>

int main()
{
putenv("TZ=Europe/Lisbon"); // replace this with your desired timezone
tzset();
return 0;
}

Lura cewa Za a iya ayyana lokuta daban-daban a cikin tsarin 'Yanki/Location', misali, 'Amurka/New_York' ko 'Turai/Berlin'.

Bayanin mataki-mataki

1. Haษ—a dakunan karatu masu mahimmanci: Kashi na farko na shirin ya ฦ™unshi guda biyu sun haษ—a da umarni. The Ana buฦ™atar ษ—akin karatu don aikin tzset da wajibi ne don aikin putenv.

2. ฦ˜ayyade babban aikin: Bayan haka, muna ayyana babban aikin wanda shine wurin shigarwa na kowane shirin C.

3. Saita Yankin Lokaci: A cikin babban aikin, muna kiran aikin putenv wanda ake amfani dashi don canzawa ko ฦ™ara canjin yanayi. A wannan yanayin, muna canza canjin 'TZ' zuwa yankin lokaci da muke son saitawa.

4. Kira tzset: Da zarar mun saita canjin 'TZ', muna kiran aikin tzset. Wannan aikin yana karanta canjin yanayi na 'TZ' kuma yana nuna waษ—annan canje-canje a cikin ayyukan da suka dogara akan lokaci.

Bayanin Laburare: time.h da stdlib.h

ฦ˜arฦ™ashin maganinmu shine mahimman ษ—akunan karatu guda biyu - 'lokaci.h' da kuma 'stdlib.h'.

lokaci.h: Wannan ษ—akin karatu yana hulษ—ar ayyuka na lokaci da kwanan wata a cikin C. Aikin 'tzset' da muke amfani da shi a lambar mu yana cikin wannan ษ—akin karatu. Ana amfani da tzset don fara bayanin yankin lokaci daga ma'aunin yanayi 'TZ'. Idan ba a saita wannan madaidaicin ba, tzset yana amfani da tsayayyen yankin lokaci (yawanci UTC).

stdlib.h: Wannan babban ษ—akin karatu ne na maฦ™asudi wanda ya haษ—a da ayyuka da suka haษ—a da shigarwar/fitarwa fayil, lambobin bazuwar, rarraba ฦ™waฦ™walwar ajiya, muhalli, da sauransu. Ayyukan 'putenv' da 'getenv' wani ษ“angare ne na wannan ษ—akin karatu. 'putenv' yana ba ku damar ฦ™ara ko canza ฦ™imar masu canjin yanayi kuma 'getenv' yana ba da ฦ™imar canjin yanayi.

Ka tuna cewa lokacin saita yankin lokaci a cikin tsarin, yana da mahimmanci a yi la'akari da wurin uwar garken da buฦ™atun aikace-aikacenku ko masu amfani.

Shafi posts:

Leave a Comment