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
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.