%-d vs%e或" no-padded"之间的Ruby日期格式差异vs"空白填充"

时间:2017-11-17 21:36:25

标签: ruby-on-rails ruby

在Ruby documentation中,有两个非常相似的值用于格式化日期(时间)字符串

  1. import numpy as np import tensorflow as tf with tf.Session() as sess: init = tf.global_variables_initializer() sess.run(init) in_size = 100 h1_size = 10 x = tf.placeholder(tf.float32,(None,in_size)) w = tf.Variable(tf.random_normal([in_size,h1_size])) b = tf.Variable(tf.ones([h1_size])) xw = tf.matmul(x,w) z = tf.add(xw,b) a = tf.nn.relu(z) yhat = sess.run(a,feed_dict={x:np.random.random([100000,in_size])}) Error:- FailedPreconditionError: Attempting to use uninitialized value Variable_12 [[Node: Variable_12/read = Identity[T=DT_FLOAT, _class=["loc:@Variable_12"], _device="/job:localhost/replica:0/task:0/cpu:0"](Variable_12)]] Caused by op 'Variable_12/read', defined at: File "C:\Users\Sachin-PC\Anaconda3\lib\site-packages\spyder\utils\ipython\start_kernel.py", line 245, in <module> main() File "C:\Users\Sachin-PC\Anaconda3\lib\site-packages\spyder\utils\ipython\start_kernel.py", line 241, in main kernel.start() File "C:\Users\Sachin-PC\Anaconda3\lib\site-packages\ipykernel\kernelapp.py", line 477, in start ioloop.IOLoop.instance().start() File "C:\Users\Sachin-PC\Anaconda3\lib\site-packages\zmq\eventloop\ioloop.py", line 177, in start super(ZMQIOLoop, self).start() File "C:\Users\Sachin-PC\Anaconda3\lib\site-packages\tornado\ioloop.py", line 888, in start handler_func(fd_obj, events) File "C:\Users\Sachin-PC\Anaconda3\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper return fn(*args, **kwargs) File "C:\Users\Sachin-PC\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 440, in _handle_events self._handle_recv() File "C:\Users\Sachin-PC\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 472, in _handle_recv self._run_callback(callback, msg) File "C:\Users\Sachin-PC\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 414, in _run_callback callback(*args, **kwargs) 描述为%-d
  2. no-padded (1..31)描述为%e
  3. 这两者之间的区别是什么?

1 个答案:

答案 0 :(得分:2)

这两者之间的区别如下:

%-d将打印出不带前导零的数字,也不打印空格:

DateTime.new(2016, 02, 01, 16, 00).strftime('%m/%-d/%Y')
> "02/1/2016"

%e将打印出前导空格,但不会打印前导零

DateTime.new(2016, 02, 01, 16, 00).strftime('%m/%e/%Y')
> "02/ 1/2016"