zoukankan      html  css  js  c++  java
  • get date tcl tk

    The method to get Date Tcltk

    proc GetDate { args } {
    #---------------------------------------------------------------
    #d_sum Return the date/time appropriately formatted
    #d_desc Uses Tcl clock command.  Return the current time if the -clock \
    argument is not used.  See Tcl clock command for explanation of formats.
    #d_opt0 -clock time
    #d_opt1 Input a time as a machine clock time in seconds
    #d_opt0 -format format
    #d_opt1 Output format can be: full (%d %b %Y  %H:%M:%S), time (%H:%M:%S) \
    date (%d %b %Y), or brief (%H:%M:%S for today or %d %b %y)

    # If there is no input secs then find the current time
    # otherwise use the input time secs  and convert to user
    # friendly format   dependent on format input
    # full        full date and time
    # time        time only
    # date        date only
    # brief        time for any time today otherwise date
    #

      set format full
      set secs {}

      set nargs [llength $args]; set n 0
      while { $n < $nargs } {
        switch -regexp -- [lindex $args $n] \
        format {
          incr n; set format [lindex $args $n]
        } clock {
          incr n; set secs [lindex $args $n]
        }
        incr n
      }

      if { $secs == "" } { set secs [clock seconds] }
      if { [llength $secs ] > 1 } {
        if { $format == "brief" } {
          return [ append time [string range $secs 0 6] [string range $secs 9 10] ]
        } else {
          return $secs
        }
      }

      if { $format == "seconds"} { return $secs }
      if { $format == "full" } {
        set date [clock format $secs -format "%d %b %Y  %H:%M:%S" ]
      } elseif { $format == "time" } {
        set date [clock format $secs -format "%H:%M:%S" ]
      } elseif { $format == "date" } {
        set date [clock format $secs -format "%d %b %Y" ]
      } elseif { $format == "brief" } {
        set today [ clock format [clock seconds] -format "%Y %j" ]
        set input [ clock format $secs -format "%Y %j" ]
        if { [lindex $input 0 ] == [lindex $today 0 ] &&
             [lindex $input 1 ] == [lindex $today 1 ] } {
          set date [clock format $secs -format "%H:%M:%S" ]
        } else {
          set date [clock format $secs -format "%d %b %y" ]
        }
      }
      return "$date"
    }


    "Starting CCP4I application [GetDate]"
  • 相关阅读:
    php安全模式笔记
    ./configure,make,make install的作用(转)
    composer自动载入类库的方式
    Specified key was too long; max key length is 1000 bytes
    海量数据中找出前k大数(topk问题)
    斐波那契数列n项的值。(递归和非递归算法Golang实现)
    基于Docker和Golang搭建Web服务器
    Nginx简单介绍以及linux下使用Nginx进行负载均衡的搭建
    php实现商城秒杀
    一致性hash (PHP)
  • 原文地址:https://www.cnblogs.com/greencolor/p/2020988.html
Copyright © 2011-2022 走看看