<p>I am getting time from <code>pod.CreationTimeStamp</code> and trying to store it in a variable.how can i store time in to string.</p>

<pre class="lang-golang prettyprint-override"><code> tmp := json_format{}
 pods, _ := clientset.CoreV1().Pods(namespace).List(v1.ListOptions{LabelSelector:app_name})

 for _, pod := range pods.Items {
     tmp.Creation_Time = append(tmp.Creation_Time,pod.CreationTimestamp) 
}
</code></pre>

<p>Its giving this error: <code>cannot convert pod.ObjectMeta.CreationTimestamp (type "k8s.io/apimachinery/pkg/apis/meta/v1".Time) to type string</code></p>

<pre><code>type json_format struct{
Creation_Time string
}
</code></pre>

Sai Vamsi
<p>To convert <code>CreationTimestamp</code> to string you can use the method <code>String()</code>.</p>

<p>Example: </p>

<pre class="lang-golang prettyprint-override"><code>timeInString := pod.CreationTimestamp.String()
</code></pre>

<p>Your code:</p>

<pre class="lang-golang prettyprint-override"><code>tmp := json_format{}
 pods, _ := clientset.CoreV1().Pods(namespace).List(v1.ListOptions{LabelSelector:app_name})

 for _, pod := range pods.Items {
     tmp.Creation_Time = append(tmp.Creation_Time,pod.CreationTimestamp.String()) 
}
</code></pre>

<p>Another correction request:</p>

<p>The <code>Creatio_Time</code> field should be slice (i.e. []string) instead of single string.</p>

<pre><code>type json_format struct{
Creation_Time []string
}
</code></pre>
