zoukankan      html  css  js  c++  java
  • C语言的setlocale和localtime函数(C++也可用)

    Example

    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
    /* setlocale example */
    #include <stdio.h>      /* printf */
    #include <time.h>       /* time_t, struct tm, time, localtime, strftime */
    #include <locale.h>     /* struct lconv, setlocale, localeconv */
    
    int main ()
    {
      time_t rawtime;
      struct tm * timeinfo;
      char buffer [80];
    
      struct lconv * lc;
    
      time ( &rawtime );
      timeinfo = localtime ( &rawtime );
    
      int twice=0;
    
      do {
        printf ("Locale is: %s
    ", setlocale(LC_ALL,NULL) );
    
        strftime (buffer,80,"%c",timeinfo);
        printf ("Date is: %s
    ",buffer);
    
        lc = localeconv ();
        printf ("Currency symbol is: %s
    -
    ",lc->currency_symbol);
    
        setlocale (LC_ALL,"");
      } while (!twice++);
    
      return 0;
    }



    One of the possible outputs when the previous code is run is:

    Locale is: C
    Date is: 01/15/07 13:33:47
    Currency symbol is: 
    -
    Locale is: English_United States.1252
    Date is: 1/15/07 1:33:47 PM
    Currency symbol is: $
    -

    http://www.cplusplus.com/reference/clocale/setlocale/

  • 相关阅读:
    完美世界笔试(动态规划,背包问题)
    腾讯笔试3
    腾讯笔试2
    腾讯笔试1
    阿里笔试1
    Merge Sorted Array
    Partition List
    Reverse Linked List II
    Remove Duplicates from Sorted List II
    白菜刷LeetCode记-704. Binary Search
  • 原文地址:https://www.cnblogs.com/findumars/p/6403523.html
Copyright © 2011-2022 走看看