IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 C Discussion :

programmation date en français


Sujet :

C

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    employé
    Inscrit en
    Juillet 2015
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : employé

    Informations forums :
    Inscription : Juillet 2015
    Messages : 3
    Points : 0
    Points
    0
    Par défaut programmation date en français
    Bonjour,


    Malgré toutes mes recherches (FAQ, http://c.developpez.com/faq/?page=Ge...ates-et-heures, etc), je ne suis pas parvenu à pouvoir programmer une date (jour mois) en français dans mon fichier. Je ne comprends pas comment et à quel endroit mettre les lignes de code ?

    Est-ce que quelqu'un pourrait m'expliquer ? (mon fichier ci-dessous)

    Merci d'avance et bonne journée.

    Stéphane.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    #include "simple_analog.h"
     
    #include "pebble.h"
     
    static Window *window;
    static Layer *s_simple_bg_layer, *s_date_layer, *s_hands_layer;
    static TextLayer *s_date_label;
    static TextLayer *battery_icon_layer;
    static TextLayer *battery_percent_layer;
    static TextLayer *bluetooth_icon_layer;
     
    static BitmapLayer *s_background_layer;
    static GBitmap *s_background_bitmap;
     
    static GPath *s_tick_paths[NUM_CLOCK_TICKS];
    static GPath *s_minute_arrow, *s_hour_arrow;
    static char s_date_buffer[20];
     
    static void bg_update_proc(Layer *layer, GContext *ctx) {
      graphics_context_set_fill_color(ctx, GColorBlack);
      graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
      graphics_context_set_fill_color(ctx, GColorWhite);
      for (int i = 0; i < NUM_CLOCK_TICKS; ++i) {
        gpath_draw_filled(ctx, s_tick_paths[i]);
      }
    }
     
    static void hands_update_proc(Layer *layer, GContext *ctx) {
      GRect bounds = layer_get_bounds(layer);
      GPoint center = grect_center_point(&bounds);
      int16_t second_hand_length = bounds.size.w / 2;
     
      time_t now = time(NULL);
      struct tm *t = localtime(&now);
      int32_t second_angle = TRIG_MAX_ANGLE * t->tm_sec / 60;
      GPoint second_hand = {
        .x = (int16_t)(sin_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.x,
        .y = (int16_t)(-cos_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.y,
      };
     
      // second hand
      graphics_context_set_stroke_color(ctx, GColorWhite);
      graphics_draw_line(ctx, second_hand, center);
     
      // minute/hour hand
      graphics_context_set_fill_color(ctx, GColorWhite);
      graphics_context_set_stroke_color(ctx, GColorBlack);
     
      gpath_rotate_to(s_minute_arrow, TRIG_MAX_ANGLE * t->tm_min / 60);
      gpath_draw_filled(ctx, s_minute_arrow);
      gpath_draw_outline(ctx, s_minute_arrow);
     
      gpath_rotate_to(s_hour_arrow, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6));
      gpath_draw_filled(ctx, s_hour_arrow);
      gpath_draw_outline(ctx, s_hour_arrow);
     
      // dot in the middle
      graphics_context_set_fill_color(ctx, GColorBlack);
      graphics_fill_rect(ctx, GRect(bounds.size.w / 2 - 1, bounds.size.h / 2 - 1, 3, 3), 0, GCornerNone);
    }
     
    static void date_update_proc(Layer *layer, GContext *ctx) {
      time_t now = time(NULL);
      struct tm *t = localtime(&now);
     
      strftime(s_date_buffer, sizeof(s_date_buffer), "%a %d %b %y", t);
      text_layer_set_text(s_date_label, s_date_buffer);
     
    }
     
    static void handle_second_tick(struct tm *tick_time, TimeUnits units_changed) {
      layer_mark_dirty(window_get_root_layer(window));
    }
     
    static void handle_bluetooth(bool connected) {
      static char bt_text[4];
      static bool bt_connected= true;
      if (connected)
      {
        strcpy(bt_text, "\xef\x84\x96");
        if (!bt_connected)
        {
          bt_connected = true;
          vibes_double_pulse();
        }
      }
      else
      {
        strcpy(bt_text, "");
        if (bt_connected)
        {
          bt_connected = false;
          vibes_long_pulse();
        }
      }
      text_layer_set_text(bluetooth_icon_layer, bt_text);
      APP_LOG(APP_LOG_LEVEL_DEBUG, "Bluetooth change: connected=%i", connected);
    }
     
    static void handle_battery(BatteryChargeState charge_state)
    {
      static char battery_icon[4];
      static char battery_text[5];
      if (charge_state.charge_percent > 80)
      {
        strcpy(battery_icon, "\xef\x84\x93");
      }
      else if (charge_state.charge_percent > 50 && charge_state.charge_percent <= 80)
      {
        strcpy(battery_icon, "\xef\x84\x94");
      }
      else if (charge_state.charge_percent > 20 && charge_state.charge_percent <= 50)
      {
        strcpy(battery_icon, "\xef\x84\x95");
      }
      else
      {
        strcpy(battery_icon, "\xef\x84\x92");
      }
      APP_LOG(APP_LOG_LEVEL_DEBUG, "Battery change: %i remaining", charge_state.charge_percent);
      snprintf(battery_text, sizeof(battery_text), "%d%%", charge_state.charge_percent);
      text_layer_set_text(battery_icon_layer, battery_icon);
      text_layer_set_text(battery_percent_layer, battery_text);
    }
     
    static void window_load(Window *window) {
      Layer *window_layer = window_get_root_layer(window);
      GRect bounds = layer_get_bounds(window_layer);
      GFont status_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_STATUS_12));
      GFont icon_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ICONS_14));
     
      s_simple_bg_layer = layer_create(bounds);
      layer_set_update_proc(s_simple_bg_layer, bg_update_proc);
      layer_add_child(window_layer, s_simple_bg_layer);
     
      //Create GBitmap, then set to created BitmapLayer
      s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND);
      s_background_layer = bitmap_layer_create(GRect(0, 0, 144, 168));
      bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap);
      layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer));
     
     
      s_date_layer = layer_create(bounds);
      layer_set_update_proc(s_date_layer, date_update_proc);
      layer_add_child(window_layer, s_date_layer);
     
      s_date_label = text_layer_create(GRect(37, 118, 80, 20));
      text_layer_set_text(s_date_label, s_date_buffer);
      text_layer_set_background_color(s_date_label, GColorBlack);
      text_layer_set_text_color(s_date_label, GColorWhite);
      text_layer_set_font(s_date_label, fonts_get_system_font(FONT_KEY_GOTHIC_18));
     
      layer_add_child(s_date_layer, text_layer_get_layer(s_date_label));
     
      s_hands_layer = layer_create(bounds);
      layer_set_update_proc(s_hands_layer, hands_update_proc);
      layer_add_child(window_layer, s_hands_layer);
     
      // Battery Percentage
      battery_percent_layer = text_layer_create(GRect(108, 4, 33, 15));
      text_layer_set_font(battery_percent_layer, status_font);
      text_layer_set_text_color(battery_percent_layer, GColorWhite);
      text_layer_set_background_color(battery_percent_layer, GColorClear);
      text_layer_set_text_alignment(battery_percent_layer, GTextAlignmentRight);
      layer_add_child(window_layer, text_layer_get_layer(battery_percent_layer));
     
      // Battery Icon
      battery_icon_layer = text_layer_create(GRect(122, 140, 15, 15));
      text_layer_set_font(battery_icon_layer, icon_font);
      text_layer_set_text_color(battery_icon_layer, GColorWhite);
      text_layer_set_background_color(battery_icon_layer, GColorClear);
      text_layer_set_text_alignment(battery_icon_layer, GTextAlignmentRight);
      layer_add_child(window_layer, text_layer_get_layer(battery_icon_layer));
     
      // Bluetooth Icon
      bluetooth_icon_layer = text_layer_create(GRect(2, 140, 15, 15));
      text_layer_set_font(bluetooth_icon_layer, icon_font);
      text_layer_set_text_color(bluetooth_icon_layer, GColorWhite);
      text_layer_set_background_color(bluetooth_icon_layer, GColorClear);
      text_layer_set_text_alignment(bluetooth_icon_layer, GTextAlignmentRight);
      layer_add_child(window_layer, text_layer_get_layer(bluetooth_icon_layer));
     
       // Events
      battery_state_service_subscribe(&handle_battery);
      bluetooth_connection_service_subscribe(&handle_bluetooth);
      time_t now = time(NULL);
      struct tm *current_time = localtime(&now);
      handle_battery(battery_state_service_peek());
      handle_bluetooth(bluetooth_connection_service_peek());
    }
     
    static void window_unload(Window *window) {
      layer_destroy(s_simple_bg_layer);
      layer_destroy(s_date_layer);
      text_layer_destroy(battery_percent_layer);
      text_layer_destroy(battery_icon_layer);
      text_layer_destroy(bluetooth_icon_layer);
     
      text_layer_destroy(s_date_label);
     
      layer_destroy(s_hands_layer);
    }
     
    static void init() {
      window = window_create();
      window_set_window_handlers(window, (WindowHandlers) {
        .load = window_load,
        .unload = window_unload,
      });
      window_stack_push(window, true);
     
      s_date_buffer[0] = '\0';
     
      // init hand paths
      s_minute_arrow = gpath_create(&MINUTE_HAND_POINTS);
      s_hour_arrow = gpath_create(&HOUR_HAND_POINTS);
     
      Layer *window_layer = window_get_root_layer(window);
      GRect bounds = layer_get_bounds(window_layer);
      GPoint center = grect_center_point(&bounds);
      gpath_move_to(s_minute_arrow, center);
      gpath_move_to(s_hour_arrow, center);
     
      for (int i = 0; i < NUM_CLOCK_TICKS; ++i) {
        s_tick_paths[i] = gpath_create(&ANALOG_BG_POINTS[i]);
      }
     
      tick_timer_service_subscribe(SECOND_UNIT, handle_second_tick);
    }
     
    static void deinit() {
      gpath_destroy(s_minute_arrow);
      gpath_destroy(s_hour_arrow);
     
      for (int i = 0; i < NUM_CLOCK_TICKS; ++i) {
        gpath_destroy(s_tick_paths[i]);
      }
     
      tick_timer_service_unsubscribe();
      window_destroy(window);
    }
     
    int main() {
      init();
      app_event_loop();
      deinit();
    }

  2. #2
    Modérateur

    Avatar de Bktero
    Homme Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Juin 2009
    Messages
    4 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués

    Informations forums :
    Inscription : Juin 2009
    Messages : 4 481
    Points : 13 679
    Points
    13 679
    Billets dans le blog
    1
    Par défaut
    Bonjour,

    Tu espères vraiment qu'on se tape tes 250 lignes de code et qu'on rajoute ce qu'il manque au bon endroit ? Il est peu probable que cela arrive.

    En revanche, si tu souhaites nous exposer clairement ton problème et nous fournir un bout de code minimaliste, alors il est probable qu'on t'aide à le faire fonctionner.

  3. #3
    Expert éminent sénior
    Avatar de Sve@r
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Février 2006
    Messages
    12 690
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Février 2006
    Messages : 12 690
    Points : 30 985
    Points
    30 985
    Billets dans le blog
    1
    Par défaut
    Bonjour
    Citation Envoyé par stephaneg70 Voir le message
    Je ne comprends pas comment et à quel endroit mettre les lignes de code ?
    A priori, je dirai "à l'endroit où tu veux afficher une date"... voire même (si c'est le cas) "à l'endroit où tu affiches déjà la date en anglais"...

    Citation Envoyé par Bktero Voir le message
    Tu espères vraiment qu'on se tape tes 250 lignes de code...
    250 ça me parait difficile. Fort heureusement il n'y en a que 247...
    Mon Tutoriel sur la programmation «Python»
    Mon Tutoriel sur la programmation «Shell»
    Sinon il y en a pleins d'autres. N'oubliez pas non plus les différentes faq disponibles sur ce site
    Et on poste ses codes entre balises [code] et [/code]

  4. #4
    Nouveau Candidat au Club
    Homme Profil pro
    employé
    Inscrit en
    Juillet 2015
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : employé

    Informations forums :
    Inscription : Juillet 2015
    Messages : 3
    Points : 0
    Points
    0
    Par défaut
    Bonjour,

    Merci pour vos réponses. Je précise pour Bktero que je ne veux nullement que quelqu'un fasse la travail à ma place (où serait le plaisir de créer un code ?), mais si je pose cette question c'est que je n'ai vraiment pas réussi à comprendre.

    J'ai fournis mes 247 lignes pour que la personne qui désire m'aider comprenne justement mon problème. Toujours pour Bktero : je suis un débutant, mais en faisant ctrl+F (rechercher) et en mettant le mot "date", on peut s'apercevoir qu'il n'y a pas beaucoup de lignes qui concerne la date. Le but de ma demande est de traduire en Français les jours et mois. Ex : monday en lundi - july en juillet.

    Pour Sve@r, merci pour ta réponse c'est les lignes ci-dessous qui comportent la date en Anglais. J'ai essayé de plusieurs manières, mais je n'y suis pas arrivé.

    Bonne journée.

    Lignes 62 à 67.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    static void date_update_proc(Layer *layer, GContext *ctx) {
      time_t now = time(NULL);
      struct tm *t = localtime(&now);
     
      strftime(s_date_buffer, sizeof(s_date_buffer), "%a %d %b %y", t);
      text_layer_set_text(s_date_label, s_date_buffer);

  5. #5
    Membre éclairé
    Avatar de Elijha
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Avril 2003
    Messages
    314
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Avril 2003
    Messages : 314
    Points : 742
    Points
    742
    Par défaut
    Bonjour,

    Je pense que strftime ne sait pas parler français

    Tu as toutes les informations dans la structure tm
    Code man localtime : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
               struct tm {
                   int tm_sec;         /* seconds */
                   int tm_min;         /* minutes */
                   int tm_hour;        /* hours */
                   int tm_mday;        /* day of the month */
                   int tm_mon;         /* month */
                   int tm_year;        /* year */
                   int tm_wday;        /* day of the week */
                   int tm_yday;        /* day in the year */
                   int tm_isdst;       /* daylight saving time */
               };
     
           The members of the tm structure are:
           tm_sec    The number of seconds after the minute, normally in the range 0 to 59, but can be up to 60 to allow for leap seconds.
           tm_min    The number of minutes after the hour, in the range 0 to 59.
           tm_hour   The number of hours past midnight, in the range 0 to 23.
           tm_mday   The day of the month, in the range 1 to 31.
           tm_mon    The number of months since January, in the range 0 to 11.
           tm_year   The number of years since 1900.
           tm_wday   The number of days since Sunday, in the range 0 to 6.
           tm_yday   The number of days since January 1, in the range 0 to 365.
           tm_isdst  A flag that indicates whether daylight saving time is in effect at the time described.  The value is positive if daylight saving time is
                     in effect, zero if it is not, and negative if the information is not available.
    Par exemple, tu peux très bien avoir les 12 chaînes des mois et des 7 jours et les indexer par tm_mday et tm_wday.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
        // Date du jour
        time_t    clock = time(NULL) ;
        struct tm *date = localtime(&clock) ;
     
        // The number of months since January, in the range 0 to 11.
        const char *strMois[] = {
          "janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"
        } ;
     
        // The number of days since Sunday, in the range 0 to 6.
        const char *strJour[] = {
          "dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"
        } ;
     
        // 1. Formatage en JJ/MM/AAAA : 07/07/2015
        printf("%.2d/%.2d/%.4d\n", date->tm_mday, date->tm_mon+1, 1900+date->tm_year) ;
     
        // 2. Formatage en JJJJ JJ MMMM AAAA : mardi 7 juillet 2015
        printf("%s %d %s %.4d\n", strJour[date->tm_wday], date->tm_mday, strMois[date->tm_mon], 1900+date->tm_year) ;
    Bonne continuation.
    - Une réponse vous a été utile ? Remerciez son auteur en cliquant le pouce vert !
    - Travailler dur n'a jamais tué personne, mais pourquoi prendre le risque (Edgar Bergen)

  6. #6
    Nouveau Candidat au Club
    Homme Profil pro
    employé
    Inscrit en
    Juillet 2015
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : employé

    Informations forums :
    Inscription : Juillet 2015
    Messages : 3
    Points : 0
    Points
    0
    Par défaut
    Bonjour Elijha,

    Merci beaucoup pour toutes ces information, je suis sûr que là je vais pouvoir avancer. Je crois que je commence à comprendre, maintenant je vais essayer et.. hop... au boulot.

    Bonne journée.

    Stéphane.

Discussions similaires

  1. [Dates] jour, mois d'une date en Français
    Par Ismail dans le forum Langage
    Réponses: 1
    Dernier message: 01/12/2006, 22h30
  2. probléme programme date
    Par conceicao dans le forum C
    Réponses: 14
    Dernier message: 15/11/2006, 17h03
  3. [SQL] date en français dans un tableau
    Par chouchouboy dans le forum PHP & Base de données
    Réponses: 12
    Dernier message: 25/06/2006, 22h56
  4. Format Date Anglais/Français
    Par macben dans le forum Oracle
    Réponses: 4
    Dernier message: 22/08/2005, 10h12
  5. Date format français
    Par coca dans le forum XMLRAD
    Réponses: 2
    Dernier message: 17/11/2003, 08h46

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo